当我第一次在数据库中插入一个值时,我总是得到这个 我怎么能避免这个请帮助
06-08 13:42:20.649: E/AndroidRuntime(31384): FATAL EXCEPTION: main
06-08 13:42:20.649: E/AndroidRuntime(31384): android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: CREATE TABLE villes(code_postal INTEGER PRIMARY KEY,nom_ville TEXT,
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1113)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:686)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1769)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1700)
06-08 13:42:20.649: E/AndroidRuntime(31384): at com.sante.masante.DbHelper.DataBaseHelper.onCreate(DataBaseHelper.java:63)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
06-08 13:42:20.649: E/AndroidRuntime(31384): at com.sante.masante.DbHelper.VilleManager.insertVille(VilleManager.java:80)
06-08 13:42:20.649: E/AndroidRuntime(31384): at com.sante.masante.DataBaseActivitys.Insert$1.onClick(Insert.java:37)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.view.View.performClick(View.java:4439)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.widget.Button.performClick(Button.java:139)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.view.View$PerformClick.run(View.java:18395)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.os.Handler.handleCallback(Handler.java:725)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.os.Handler.dispatchMessage(Handler.java:92)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.os.Looper.loop(Looper.java:176)
06-08 13:42:20.649: E/AndroidRuntime(31384): at android.app.ActivityThread.main(ActivityThread.java:5317)
06-08 13:42:20.649: E/AndroidRuntime(31384): at java.lang.reflect.Method.invokeNative(Native Method)
06-08 13:42:20.649: E/AndroidRuntime(31384): at java.lang.reflect.Method.invoke(Method.java:511)
06-08 13:42:20.649: E/AndroidRuntime(31384): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
06-08 13:42:20.649: E/AndroidRuntime(31384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
06-08 13:42:20.649: E/AndroidRuntime(31384): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
如果堆栈跟踪是任何指示,则create table语句不完整。看起来您没有正确关闭create语句,而是用逗号而不是右括号结束它。