开发者社区 问答 正文

在SQlite查询中使用变量

使用了下面的方法:
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。
但是没实现。谢谢

展开
收起
a123456678 2016-07-18 14:06:41 3718 分享 版权
1 条回答
写回答
取消 提交回答
  • String value = "textForQuery"
    Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE + " where " + KEY_LOCATION + " like '%%"+value+"%%'", null);

    2019-07-17 19:57:48
    赞同 展开评论