我面臨的一個問題是插入一個問題,在Android中使用sqlite數據庫中的單引號插入文本。它返回以下錯誤。如何插入單個文本的文本到android中的sqlite數據庫?
06-21 15:21:55.644: E/AndroidRuntime(16328): android.database.sqlite.SQLiteException: near
"re": syntax error (code 1): , while compiling: select * from tbl_chatHistory where
chat_date = '1.403344315631E12' and chat_time = '1.403344315635E12' and chat_text =
'you're'
請幫忙。
****************編輯*************************
public boolean checkChatExists(String date, String time, String chat) {
boolean result = false;
String selectQuery = "select * from tbl_chatHistory where chat_date = '"+date+"'
and chat_time = '"+time+"' and chat_text = '"+chat+"'";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
result = true;
} else {
result = false;
}
cursor.close();
return result;
}
發佈您的代碼...並考慮使用參數化查詢而不是注入式原始SQL。浮點數作爲日期/時間似乎也不是一個好主意。 – laalto
@laalto用代碼編輯問題。請幫忙。 – Sundeep
您發佈的代碼沒有問題。基於ContentValues的方法已經自動使用參數化查詢。問題出在'select',而不是'insert'。 – laalto