2014-02-14 36 views
0

此查詢給了我錯誤"no such column: ANTIPASTI"我不明白爲什麼WHERE節給出了這個錯誤:Android的查詢SQLite的奇怪的錯誤

String sql = "SELECT _id, prodotto, reparto FROM Prodotti WHERE reparto=ANTIPASTI"; 

LOG CAT:

02-14 13:28:39.376: E/AndroidRuntime(1987): FATAL EXCEPTION: main 02-14 13:28:39.376: E/AndroidRuntime(1987): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ristor/com.example.ristor.Interno_tavolo}: android.database.sqlite.SQLiteException: no such column: ANTIPASTI (code 1): , while compiling: SELECT _id, prodotto, reparto FROM Prodotti WHERE reparto=ANTIPASTI 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread.access$600(ActivityThread.java:141) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.os.Handler.dispatchMessage(Handler.java:99) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.os.Looper.loop(Looper.java:137) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread.main(ActivityThread.java:5103) 02-14 13:28:39.376: E/AndroidRuntime(1987): at java.lang.reflect.Method.invokeNative(Native Method) 02-14 13:28:39.376: E/AndroidRuntime(1987): at java.lang.reflect.Method.invoke(Method.java:525) 02-14 13:28:39.376: E/AndroidRuntime(1987): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 02-14 13:28:39.376: E/AndroidRuntime(1987): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 02-14 13:28:39.376: E/AndroidRuntime(1987): at dalvik.system.NativeStart.main(Native Method) 02-14 13:28:39.376: E/AndroidRuntime(1987): Caused by: android.database.sqlite.SQLiteException: no such column: ANTIPASTI (code 1): , while compiling: SELECT _id, prodotto, reparto FROM Prodotti WHERE reparto=ANTIPASTI 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253) 02-14 13:28:39.376: E/AndroidRuntime(1987): at com.example.ristor.Interno_tavolo.listaProdotti(Interno_tavolo.java:55) 02-14 13:28:39.376: E/AndroidRuntime(1987): at com.example.ristor.Interno_tavolo.onCreate(Interno_tavolo.java:46) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.Activity.performCreate(Activity.java:5133) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 02-14 13:28:39.376: E/AndroidRuntime(1987): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 02-14 13:28:39.376: E/AndroidRuntime(1987): ... 11 more

+0

使用''ANTIPASTI''。由於該列是一個「String」,因此您應該將其與「String」進行比較。 – cosmincalistru

+0

你確定在「Prodotti」表中有「ANTIPASTI」列嗎? –

回答

1

由於ANTIPASTI是一個字符串,你需要把它放在下面的單引號'中。

String sql = "SELECT _id, prodotto, reparto FROM Prodotti WHERE reparto = 'ANTIPASTI' ";