5

我正在尝试从 android sqlite 数据库中检索数据,但它的例外是没有这样的列:


Sqlite 选择查询是-:

c=db.rawQuery("Select Name from stud Where Address="+a,null);


例外情况:-

07-04 18:07:00.888: I/Database(648): sqlite returned: error code = 1, msg = no such column: aa
07-04 18:07:00.910: D/AndroidRuntime(648): Shutting down VM
07-04 18:07:00.910: W/dalvikvm(648): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-04 18:07:00.948: E/AndroidRuntime(648): FATAL EXCEPTION: main
07-04 18:07:00.948: E/AndroidRuntime(648): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.StudentInfoManagement/com.my.StudentInfoManagement.ListData}: android.database.sqlite.SQLiteException: no such column: aa: , while compiling: Select Name from stud Where Address=aa
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.os.Looper.loop(Looper.java:123)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-04 18:07:00.948: E/AndroidRuntime(648):  at java.lang.reflect.Method.invokeNative(Native Method)
07-04 18:07:00.948: E/AndroidRuntime(648):  at java.lang.reflect.Method.invoke(Method.java:507)
07-04 18:07:00.948: E/AndroidRuntime(648):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-04 18:07:00.948: E/AndroidRuntime(648):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-04 18:07:00.948: E/AndroidRuntime(648):  at dalvik.system.NativeStart.main(Native Method)
07-04 18:07:00.948: E/AndroidRuntime(648): Caused by: android.database.sqlite.SQLiteException: no such column: aa: , while compiling: Select Name from stud Where Address=aa
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
07-04 18:07:00.948: E/AndroidRuntime(648):  at com.my.StudentInfoManagement.DataHelper.show(DataHelper.java:86)
07-04 18:07:00.948: E/AndroidRuntime(648):  at com.my.StudentInfoManagement.ListData.onCreate(ListData.java:19)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-04 18:07:00.948: E/AndroidRuntime(648):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-04 18:07:00.948: E/AndroidRuntime(648):  ... 11 more
07-04 18:07:03.140: I/Process(648): Sending signal. PID: 648 SIG: 9
4

2 回答 2

13

这仅仅是因为你的 sql 查询错误。查询文本时,您需要在查询字符串周围添加单引号。

您的行应为:

c=db.rawQuery("Select Name from stud Where Address='"+a+"'",null);
于 2012-07-04T13:11:09.580 回答
0

如果您正在使用,string那么您必须用单引号表示它,例如:

Cursor cursor = db.rawQuery("SELECT '"+WINNER+"' FROM '"+TABLE.trim()+"' WHERE 
       country1='"+c1.trim()+"' AND Country2='"+c2.trim()+"'", null);

如果您代表一个int值,那么您可以像这样简单地使用: +num+

于 2014-12-01T12:15:29.610 回答