0
使用下面的代碼我可以檢查一行是否包含單個字符串(字符串a),但我將如何檢查一行是否等於任何字符串(字符串a或b)?Sqlite,如何檢查一行是否包含字符串
public Cursor fetchMyList() {
String[] columns = { KEY_ROWID, KEY_CATEGORY, KEY_SUMMARY,
KEY_DESCRIPTION, KEY_EMAIL };
String selection = "description=?";
String a = "blue";
String b = "red";
String[] selectionArgs = { a };
// String[] selectionArgs = { a , b}; ///tried this dont work!!
Cursor cursor = null;
try {
cursor = database.query(DATABASE_TABLE, columns, selection,
selectionArgs, null, null, null);
} catch (Exception e) {
e.printStackTrace();
}
int numberOfRows = cursor.getCount();
if (numberOfRows <= 0) {
return cursor;
}
return cursor;
}
非常感謝你我花了數小時尋找這個答案,是否有我不應該使用異常的原因? – steo
不客氣。 http://stackoverflow.com/questions/2416316/why-is-the-catchexception-almost-always-a-bad-idea – m0skit0