2014-03-12 57 views
1

我想這個查詢:的Android SQLite的排除領域

Cursor c = myDB.rawQuery("SELECT * FROM " + tableName + " WHERE Field5 NOT LIKE " + 
Arrays.toString(ALQu.toArray()).replace("[", "(").replace("]", ")") + 
"ORDER BY RANDOM() LIMIT 1", null); 

,但我得到了以下錯誤:

03-12 18:12:34.469: E/AndroidRuntime(16604): android.database.sqlite.SQLiteException: near ",": syntax error: , while compiling: SELECT * FROM TableQ WHERE Field5 NOT LIKE (6, 9) ORDER BY RANDOM() LIMIT 1

我儘量排除已選中的字段。我將數據添加到ArrayList中。我看不出問題在哪裏。你能幫忙嗎?

編輯:

是的,這是 「NOT IN」,我不知道爲什麼我沒有嘗試它,謝謝

+1

我不要認爲'NOT LIKE(6,9)'是SQLite有效 – gunar

+0

也許你的意思是「NOT IN(6,9)」? –

回答

0

更改不喜歡NOT IN:

Cursor c = myDB.rawQuery("SELECT * FROM " + tableName + " WHERE Field5 NOT IN " + 
    Arrays.toString(ALQu.toArray()).replace("[", "(").replace("]", ")") + 
    "ORDER BY RANDOM() LIMIT 1", null); 
+0

是的,我做了,謝謝。 – Yves

+0

如果我幫了你,你能接受我的答案嗎?謝謝 –