SQLITE创建表错误

时间:2010-11-23 01:26:58

标签: android sqlite

这是我用来创建表的代码

 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);";

logcat显示:

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 to 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)

2 个答案:

答案 0 :(得分:7)

GROUP是保留关键字。使用其他名称。

答案 1 :(得分:0)

您应该在DATABASE_CREATE命令中使用确切的空格。

示例:

private static final String DATABASE_CREATE = "create table " + TABLE_COMMENTS + "(" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_COMMENT + " TEXT NOT NULL" + ");";