2012-01-11 209 views
0

我正在使用Android 2.2與SQLite 3.我正在使用下面的查詢,但它與我已粘貼的錯誤日誌錯誤。SQLite SQL查詢中的語法錯誤

我對我要出錯的地方毫無頭緒。

我的代碼:

private static final String table_post_natal_care= new String("create table post_natal_care ("+ 
    "number_of_meal text ,"+ 
    "excessive_bleeding text ,"+ 
    "number_of_pads_changed text ,"+ 
    "baby_warm text ,"+ 
    "number_of_times_baby_fed text ,"+ 
    "baby_crying text ,"+ 
    "number_of_times_baby_urinating text ,"+ 
    "mother_temperature text ,"+ 
    "mother_discharge text ,"+ 
    "mother_speaking_pattern text ,"+ 
    "mother_fits text ,"+ 
    "mother_perceives_milk text ,"+ 
    "mother_nipples text ,"+ 
    "mother_skin_color text ,"+ 
    "vagina_tearing text ,"+ 
    "baby_swollen_eyes text ,"+ 
    "baby_weight text ,"+ 
    "baby_temperature text ,"+ 
    "baby_pustules text ,"+ 
    "baby_skin text ,"+ 
    "baby_eyes text ,"+ 
    "baby_feeding text ,"+ 
    "baby_limbs text ,"+ 
    "baby_abdomen text ,"+ 
    "baby_cry text ,"+ 
    "baby_chest text,"+ 
    "baby_umbilicius text,"+ 
    "baby_vommit text"+ 
    ")"); 

LogTrace:

I/iDoc ( 277): returning createContentValues_pnc_visit=Yes 
I/Database( 277): sqlite returned: error code = 1, msg = near ")": syntax error 
D/dalvikvm( 277): GC_FOR_MALLOC freed 2186 objects/720424 bytes in 56ms 
E/Database( 277): Error inserting =Yes 
E/Database( 277): android.database.sqlite.SQLiteException: near ")": syntax error: , while compiling: INSERT INTO post_natal_care() VA 
LUES(?); 
E/Database( 277):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
E/Database( 277):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91) 
E/Database( 277):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64) 
E/Database( 277):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80) 
E/Database( 277):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36) 
E/Database( 277):  at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145) 
E/Database( 277):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536) 
E/Database( 277):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410) 
E/Database( 277):  at org.atl.db.DBAdapter.insertPNCVisit(DBAdapter.java:824) 
E/Database( 277):  at com.accenturelabs.idoc.PostNatalCheck.insertPNCData(PostNatalCheck.java:363) 
E/Database( 277):  at com.accenturelabs.idoc.PostNatalCheck.access$6(PostNatalCheck.java:360) 
E/Database( 277):  at com.accenturelabs.idoc.PostNatalCheck$4.onClick(PostNatalCheck.java:149) 
E/Database( 277):  at android.view.View.performClick(View.java:2408) 
E/Database( 277):  at android.view.View$PerformClick.run(View.java:8816) 
E/Database( 277):  at android.os.Handler.handleCallback(Handler.java:587) 
E/Database( 277):  at android.os.Handler.dispatchMessage(Handler.java:92) 
E/Database( 277):  at android.os.Looper.loop(Looper.java:123) 
E/Database( 277):  at android.app.ActivityThread.main(ActivityThread.java:4627) 
E/Database( 277):  at java.lang.reflect.Method.invokeNative(Native Method) 
E/Database( 277):  at java.lang.reflect.Method.invoke(Method.java:521) 
E/Database( 277):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
E/Database( 277):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
E/Database( 277):  at dalvik.system.NativeStart.main(Native Method) 

回答

1

您的此錯誤日誌。

E/Database( 277): android.database.sqlite.SQLiteException: near ")": syntax error: , while compiling: INSERT INTO post_natal_care() VA

它清楚地表明,您在將數據插入表中而不是創建時遇到問題。所以,檢查你的插入查詢。

+0

+1:這是真正的問題!閱讀錯誤信息,而不是猜測問題出在哪裏。 – 2012-01-11 07:21:08

+0

我填充的bean爲null。 – bhalkian 2012-01-11 09:06:07

2

我覺得你的查詢字符串是不好的。看不清楚,我不明白你桌子的主要關鍵是什麼,我想你錯過了「;」在查詢

一些代碼示例樣的結尾:

private static final String TODOLIST_TABLE_CREATE = "create table TODOLIST" 
      +" (_id integer primary key autoincrement, " 
      +"summary text not null, " 
      +"description text, " 
      +"categoryid integer REFERENCES CATEGORY(_id), " 
      +"priority integer, " 
      +"abdeadline text, " 
      +"goaldeadline text, " 
      +"remindab integer, " 
      +"remindgoal integer);"; 

使用新的生產線,使您的查詢字符串清晰。

+0

+1有關缺少識別(PK)信息的評論。 – 2012-01-11 07:19:59