o19830015 2013-03-21 03:36 采纳率: 12.5%
浏览 8161
已采纳

在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
但是没实现。谢谢

  • 写回答

2条回答 默认 最新

  • CuGBabyBeaR 2013-03-21 06:35
    关注
    String value = "textForQuery"
    Cursor cursor = db.rawQuery("select * from " + smokinDBOpenHelper.INCIDENTS_TABLE + " where " + KEY_LOCATION + " like '%%"+value+"%%'", null);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?