我想知道,我的代码会运行,但它不会像我想要的那样返回结果。例如我的
上的数据column1是:热狗,培根,奶酪
我想搜索培根。像查询无法找到培根。但如果我搜索奶酪或热狗之类的查询可以找到它。我想如果这个词用逗号包围。我需要做什么?
public ArrayList<String> getrecom(int recom1) {
ArrayList<String> result = new ArrayList<String>();
SQLiteDatabase db = dbHelperFoods.getWritableDatabase();
String selectQuery = "SELECT * FROM "+ recom.TABLE+" WHERE " +KEY_recom+ " LIKE '%"+recom1+"%'";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
result.add(cursor.getString(cursor.getColumnIndex("name")));
while (cursor.moveToNext()) {
result.add(cursor.getString(cursor.getColumnIndex("name")));
}
}
cursor.close();
db.close();
return result;
}