您好我想根据用户ID在两个日期之间获取记录。
我提取记录的查询:
System.out.println("in data function");
Cursor curCalllog = db.rawQuery("SELECT KEY_ID FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate + " BETWEEN ? AND ?", new String[]{startdate, enddate});
请帮我查询,因为它显示错误 - no such column id
我的查询有什么问题。请帮帮我。
Log Cat
05-07 12:33:41.294: W/System.err(29046): User id : 1
05-07 12:33:41.294: I/System.out(29046): date from7-1-2013
05-07 12:33:41.304: I/System.out(29046): date to7-7-2013
05-07 12:33:41.304: W/System.err(29046): on click
05-07 12:33:42.224: I/System.out(29046): uid for history1
05-07 12:33:42.354: I/System.out(29046): in data function
05-07 12:33:42.354: E/SQLiteLog(29046): (1) no such column: KEY_ID
05-07 12:33:42.634: E/AndroidRuntime(29046): FATAL EXCEPTION: main
05-07 12:33:42.634: E/AndroidRuntime(29046): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raintek.customerhome/com.raintek.customerhome.History}: android.database.sqlite.SQLiteException: no such column: KEY_ID (code 1): , while compiling: SELECT KEY_ID FROM Airline WHERE bookingdate BETWEEN ? AND ?
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.os.Handler.dispatchMessage(Handler.java:99)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.os.Looper.loop(Looper.java:137)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-07 12:33:42.634: E/AndroidRuntime(29046): at java.lang.reflect.Method.invokeNative(Native Method)
05-07 12:33:42.634: E/AndroidRuntime(29046): at java.lang.reflect.Method.invoke(Method.java:511)
05-07 12:33:42.634: E/AndroidRuntime(29046): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-07 12:33:42.634: E/AndroidRuntime(29046): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-07 12:33:42.634: E/AndroidRuntime(29046): at dalvik.system.NativeStart.main(Native Method)
05-07 12:33:42.634: E/AndroidRuntime(29046): Caused by: android.database.sqlite.SQLiteException: no such column: KEY_ID (code 1): , while compiling: SELECT KEY_ID FROM Airline WHERE bookingdate BETWEEN ? AND ?
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
05-07 12:33:42.634: E/AndroidRuntime(29046): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
我的表
db.execSQL(" CREATE TABLE " + KK_AIRLINEBOOK + " (" + KEY_SrNo
+ " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KEY_ID + " INTEGER , " + KEY_BNAME + " TEXT , "
+ KEY_Bookingdate
+ " TEXT, " + KEY_Pickupaddress + " TEXT, " + KEY_City
+ " TEXT, " + KEY_AirportType + " TEXT, "+ KEY_Trip + " TEXT, " + KEY_Cabr + " TEXT , "
+ KEY_FlightDate + " TEXT, " + KEY_FlightTime + " TEXT, " + KEY_CabDate
+ " TEXT, " + KEY_PickupTime + " TEXT, " + KEY_TotalSeats
+ " INTEGER, " + KEY_Charges + " INTEGER , "
+ " FOREIGN KEY(srno) REFERENCES KK_REGISTRATION(id));");
答案 0 :(得分:0)
更改
Cursor curCalllog = db.rawQuery("SELECT KEY_ID FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate + " BETWEEN ? AND ?", new String[]{startdate, enddate});
到
Cursor curCalllog = db.rawQuery("SELECT "+KEY_ID+" FROM "+ KK_AIRLINEBOOK +
" WHERE " + KEY_Bookingdate + " BETWEEN ? AND ?", new String[]{startdate, enddate});
希望您了解问题发生的原因。它正在寻找KEY_ID列。不适用于KEY_ID包含的值。
请参阅logcat:
Caused by: android.database.sqlite.SQLiteException: no such column: KEY_ID (code 1): , while compiling: SELECT KEY_ID FROM Airline WHERE bookingdate BETWEEN ? AND ?