Android의 sqlite db에 작은 따옴표가있는 텍스트를 삽입 할 때 문제를 삽입하는 데 문제가 있습니다. 다음 오류를 반환합니다.
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'
도와주세요.
**************** EDITED *************************
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 문자열 리터럴 '
에서 ''
.
그러나 매개 변수화 된 쿼리를 사용하는 것이 좋습니다. 문자열 리터럴을로 바꾸고 배열 ?
의 값을 제공하십시오 bindArgs
. 예를 들면 :
String selectQuery = "select * from tbl_chatHistory where chat_date = ? and chat_time = ? and chat_text = ?";
Cursor cursor = database.rawQuery(selectQuery, new String[] { date, time, chat });
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다