unrecognized token: "78e649fe"

記錄一下 關於Android  sqlite報unrecognized token: "78e649fe"錯誤的解決方案

這個表示你的sql語句有問題

我出現的問題是

SQLiteDatabase db = dbHelper.getWritableDatabase();
int amount=0;//用來判斷uuid是否存在
Cursor cursor = db.rawQuery("select * from user where uuid = "+res, null);//res是登陸返回的uuid
amount=cursor.getCount();

這樣寫就會報錯,原因在於"select * from user where uuid = " + res 

解決方案:

1:查詢非引用類型的

如查詢ffffff-ffff-gggg的所有信息

則爲"select * from user where uuid = 'ffffff-ffff-gggg'"

2:查詢引用類型的

如將fff-ffff-gggg保存在了res中

則爲"select * from user where uuid = ?", new String[]{res}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章