android.database.sqlite.SQLiteException:没有这样的列:aa :,编译时:从stud中选择Name Where Address = aa

时间:2012-07-04 13:07:48

标签: android

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

<小时/> 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

2 个答案:

答案 0 :(得分:13)

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

您的行应为:

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

答案 1 :(得分:0)

如果您使用string,则必须使用单引号表达:

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

如果您要表示int值 然后你就可以这样使用:+num+