我有一個數據庫和一個方法來從每個表中獲取所有值。Sqlite數據庫查詢返回null
不過,我想只得到錶行,其中路線= 5(例如)
這是我的查詢:
Cursor cursor = db.query(TABLE_NAME_ROUTES, new String[] {"id","route","busstop","longitude","latitude"}, "route" + "=" + busroute , null, null, null, null);
我已經嘗試噸不同的版本WHERE子句但是似乎沒有工作,因爲返回列表的大小爲0,當它應該是關於大小20
編輯:
一行改成了這樣:
Cursor cursor = db.query(TABLE_NAME_ROUTES, new String[] {"id","route","busstop","longitude","latitude"}, "route" + "=`"+ busroute+"`" , null, null, null, null);
日誌從logcat的
05-02 18:14:23.396: E/SQLiteLog(15408): (1) no such column: 5
05-02 18:14:23.396: D/AndroidRuntime(15408): Shutting down VM
05-02 18:14:23.396: W/dalvikvm(15408): threadid=1: thread exiting with uncaught exception (group=0x40cee300)
05-02 18:14:23.400: E/AndroidRuntime(15408): FATAL EXCEPTION: main
05-02 18:14:23.400: E/AndroidRuntime(15408): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mso.master/com.mso.master.MainActivity}: android.database.sqlite.SQLiteException: no such column: 5 (code 1): , while compiling: SELECT id, route, busstop, longitude, latitude FROM routes WHERE route=`5`
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread.access$600(ActivityThread.java:142)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.os.Looper.loop(Looper.java:137)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread.main(ActivityThread.java:4931)
05-02 18:14:23.400: E/AndroidRuntime(15408): at java.lang.reflect.Method.invokeNative(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408): at java.lang.reflect.Method.invoke(Method.java:511)
05-02 18:14:23.400: E/AndroidRuntime(15408): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
05-02 18:14:23.400: E/AndroidRuntime(15408): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
05-02 18:14:23.400: E/AndroidRuntime(15408): at dalvik.system.NativeStart.main(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408): Caused by: android.database.sqlite.SQLiteException: no such column: 5 (code 1): , while compiling: SELECT id, route, busstop, longitude, latitude FROM routes WHERE route=`5`
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
05-02 18:14:23.400: E/AndroidRuntime(15408): at com.mso.master.DataManipulator.selectRoute(DataManipulator.java:167)
05-02 18:14:23.400: E/AndroidRuntime(15408): at com.mso.master.DBaccess.getBusRoute(DBaccess.java:43)
05-02 18:14:23.400: E/AndroidRuntime(15408): at com.mso.master.MainActivity.onCreate(MainActivity.java:130)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.Activity.performCreate(Activity.java:5008)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
05-02 18:14:23.400: E/AndroidRuntime(15408): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
05-02 18:14:23.400: E/AndroidRuntime(15408): ... 11 more
查詢有去無回'null' ,而是它將返回空的光標 – Pragnani 2013-05-02 15:51:56
你的數據庫表中的路由類型是什麼?是Text還是INTEGER? – Pragnani 2013-05-02 15:55:50
類型的路線是TEXT – Maggie 2013-05-02 16:00:37