2011-10-20 64 views
0

我無法從數據庫中檢索數據 - 儘管我更改了一些更改,但是我得到的建議也是我的查詢無法正常工作。下面是我的SQL查詢,並logcat的錯誤Android SQL查詢不適用於從DataBase中獲取數據

SQL查詢: -

Cursor cur3 = db3.rawQuery("SELECT "+pretestTable+"."+columnID+","+ 
       " "+pretestTable+"."+DDL_Testing_Session+","+ 
       " "+pretestTable+"."+Text_Reason+","+ 
       " "+pretestTable+"."+Text_Howmany+","+ 
       " "+pretestTable+"."+Text_Ques1+","+ 
       " "+pretestTable+"."+RBL_Ques2a+","+ 
       " "+pretestTable+"."+RBL_Ques2b+","+ 
       " "+pretestTable+"."+RBL_Ques3+","+ 
       " "+pretestTable+"."+TXT_Ques4+","+ 
       " "+pretestTable+"."+RBL_Ques5+","+ 
       " "+pretestTable+"."+RBL_Ques6+","+ 
       " "+pretestTable+"."+RBL_Ques7+","+ 
       " "+pretestTable+"."+RBL_Ques8+","+ 
       " "+pretestTable+"."+RBL_Ques9+","+ 
       " "+pretestTable+"."+DDL_Sick+","+ 
       " "+pretestTable+"."+TXT_Ques11+","+ 
       " "+pretestTable+"."+RBL_Ques12+","+ 
       " "+pretestTable+"."+TXT_Ques13+","+ 
       " "+pretestTable+"."+TXT_Ques14+","+ 
       " "+pretestTable+"."+RBL_Ques15+","+ 
       " "+pretestTable+"."+RBL_Ques16+","+ 
       " "+pretestTable+"."+RBL_Ques17+","+ 
       " "+pretestTable+"."+TXT_Ques18+","+ 
       " "+pretestTable+"."+TXT_Vct+" FROM "+pretestTable+"SELECT "+fingerTable+"."+Template11+"FROM"+fingerTable+" WHERE " + pretestTable+"."+columnID+" = "+fingerTable+"."+Template11+" AND "+pretestTable+"."+"pretest_id=?" , null); 

logcat的錯誤:---

10-20 23:07:34.771: ERROR/AndroidRuntime(1296): FATAL EXCEPTION: main 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.a1technology.remoteid/com.a1technology.remoteid.Screening}: android.database.sqlite.SQLiteException: near ".": syntax error: , while compiling: SELECT tbl_pre_test.ID, tbl_pre_test.ddlTestingSession, tbl_pre_test.txtReason, tbl_pre_test.txthowmany, tbl_pre_test.txtques1, tbl_pre_test.rblques2a, tbl_pre_test.rblques2b, tbl_pre_test.rblques3, tbl_pre_test.txtques4, tbl_pre_test.rblques5, tbl_pre_test.rblques6, tbl_pre_test.rblques7, tbl_pre_test.rblques8, tbl_pre_test.rblques9, tbl_pre_test.ddlsick, tbl_pre_test.txtques11, tbl_pre_test.rblques12, tbl_pre_test.txtques13, tbl_pre_test.txtques14, tbl_pre_test.rblques15, tbl_pre_test.rblques16, tbl_pre_test.rblques17, tbl_pre_test.txtques18, tbl_pre_test.txtVCT FROM tbl_pre_testSELECT tbl_finger.templateFROMtbl_finger WHERE tbl_pre_test.ID = tbl_finger.template AND tbl_pre_test.pretest_id=? 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.os.Handler.dispatchMessage(Handler.java:99) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.os.Looper.loop(Looper.java:123) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread.main(ActivityThread.java:3647) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at java.lang.reflect.Method.invokeNative(Native Method) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at java.lang.reflect.Method.invoke(Method.java:507) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at dalvik.system.NativeStart.main(Native Method) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296): Caused by: android.database.sqlite.SQLiteException: near ".": syntax error: , while compiling: SELECT tbl_pre_test.ID, tbl_pre_test.ddlTestingSession, tbl_pre_test.txtReason, tbl_pre_test.txthowmany, tbl_pre_test.txtques1, tbl_pre_test.rblques2a, tbl_pre_test.rblques2b, tbl_pre_test.rblques3, tbl_pre_test.txtques4, tbl_pre_test.rblques5, tbl_pre_test.rblques6, tbl_pre_test.rblques7, tbl_pre_test.rblques8, tbl_pre_test.rblques9, tbl_pre_test.ddlsick, tbl_pre_test.txtques11, tbl_pre_test.rblques12, tbl_pre_test.txtques13, tbl_pre_test.txtques14, tbl_pre_test.rblques15, tbl_pre_test.rblques16, tbl_pre_test.rblques17, tbl_pre_test.txtques18, tbl_pre_test.txtVCT FROM tbl_pre_testSELECT tbl_finger.templateFROMtbl_finger WHERE tbl_pre_test.ID = tbl_finger.template AND tbl_pre_test.pretest_id=? 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at com.a1technology.remoteid.Screening.onCreate(Screening.java:320) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586) 
10-20 23:07:34.771: ERROR/AndroidRuntime(1296):  ... 11 more 
+0

歡迎堆棧溢出。如果某個特定回覆有幫助,請立即投票。如果您發現回覆能夠充分回答您的問題,請接受。 –

+0

[Android數據庫遊標傳遞空值]的可能重複(http://stackoverflow.com/questions/7880751/android-database-cursor-passing-null-values) –

回答

0

你的SQL查詢缺少空間。這:

FROM tbl_pre_testSELECT tbl_finger.templateFROMtbl_finger WHERE tbl_pre_test.ID 

需要是這樣的:

FROM tbl_pre_test SELECT tbl_finger.template FROM tbl_finger WHERE tbl_pre_test.ID 
+0

SELECT ... SELECT ...作爲一個語句?這將在SQLite上工作嗎?恕我直言,這些是兩個單獨的陳述。 –

相關問題