SQLITE create table error
this is my code used to create table
private static final String DATABASE_CREATE =
"create table notes (_id integer primary key autoincrement,"
+ "title text not null, body text not null,email text not null,group text);";
the logcat shows:
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): FATAL EXCEPTION: main
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): java.lang.RuntimeException: Unable t开发者_C百科o start activity ComponentInfo{com.android/com.android.managecontact}: android.database.sqlite.SQLiteException: near "group": syntax error: , while compiling: SELECT _id, title, body, email, group FROM notes ORDER BY title
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.os.Looper.loop(Looper.java:123)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at java.lang.reflect.Method.invoke(Method.java:521)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at dalvik.system.NativeStart.main(Native Method)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): Caused by: android.database.sqlite.SQLiteException: near "group": syntax error: , while compiling: SELECT _id, title, body, email, group FROM notes ORDER BY title
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at com.android.database.fetchAllNotes(database.java:156)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at com.android.managecontact.fillData(managecontact.java:118)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at com.android.managecontact.onCreate(managecontact.java:89)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-23 08:22:32.992: ERROR/AndroidRuntime(1008): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
GROUP is a reserved keyword. Use a different name.
You should use exact spaces in the DATABASE_CREATE command.
Example :
private static final String DATABASE_CREATE = "create table " + TABLE_COMMENTS + "(" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMMENT + " TEXT NOT NULL" + ");";
精彩评论