你认为我的问题是什么。
我正在查询 sqlite 数据库。 此代码不会给出任何结果。
String sql = " select _id from MYTABLE where _id = ? ";
Cursor cur = mDb.rawQuery(sql, new String[] {"5653"}) ;
但是如果我执行不带参数的查询,如下所示:
String sql = " select _id from MYTABLE where _id = 5653 ";
Cursor cur = mDb.rawQuery(sql, null) ;
按预期返回一行。
非常感谢。
最佳答案
发生这种情况是因为这些值被绑定(bind)为字符串,并且该列是(我猜测)一个 int。所以 where 子句最终会变成
where _id = "5653"
来自选择参数的 rawQuery javadoc -
You may include ?s in where clause in the query, which will be replaced by the values from selectionArgs. The values will be bound as Strings.
关于Android Sqlite 没有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14915050/