使用了下面的方法:
public String getCount() {
SQLiteDatabase db = smokinDBOpenHelper.getWritableDatabase();
String w = "Home";
Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE +
" where " + KEY_LOCATION + " = 'Home'", null);
int i = cursor.getCount();
String s = ("You have " + i + " entries in this column");
return s;
}
我希望這個查詢能使用變量,現在用的是特定的硬編碼字符“home”
我用過+ {w}
+ {w%}
+ w
。
但是沒實現。謝謝
String value = "textForQuery"
Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE + " where " + KEY_LOCATION + " like '%%"+value+"%%'", null);