每当我尝试查询其中包含引号的词组时,我都会收到错误,例如John's day
。我该如何处理?
这是我的查询
Cursor c = db.query(EVENTS_TABLE, new String[] {ID,EVENT,DATE,REAL_START_TIME,REAL_END_TIME}
,EVENT + "='" +name+"'",null,null,null,null);
名称为John's day
logcat的
01-05 12:25:17.551: E/AndroidRuntime(17085): android.database.sqlite.SQLiteException: near "s": syntax error: , while compiling: SELECT _id, event, date, rstime, retime FROM Events_Table WHERE event='Martin Luther King, Jr's Day'
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
01-05 12:25:17.551: E/AndroidRuntime(17085): at com.app.notifyme.CalendarDB.getId(CalendarDB.java:243)
01-05 12:25:17.551: E/AndroidRuntime(17085): at com.app.notifyme.Calendar.getRow(Calendar.java:378)
01-05 12:25:17.551: E/AndroidRuntime(17085): at com.app.notifyme.Calendar$3.onItemLongClick(Calendar.java:85)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.widget.AbsListView.performLongPress(AbsListView.java:2580)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:2530)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.os.Handler.handleCallback(Handler.java:605)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.os.Looper.loop(Looper.java:137)
01-05 12:25:17.551: E/AndroidRuntime(17085): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-05 12:25:17.551: E/AndroidRuntime(17085): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 12:25:17.551: E/AndroidRuntime(17085): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 12:25:17.551: E/AndroidRuntime(17085): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-05 12:25:17.551: E/AndroidRuntime(17085): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-05 12:25:17.551: E/AndroidRuntime(17085): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
为每个显示的内容使用两个引号。例子:
SELECT 'Frank''s Oracle site' AS text FROM DUAL;
TEXT: Franks的Oracle网站