![](/img/trans.png)
[英]Android SQLite DISTINCT query not working with rawQuery()
[英]why rawQuery is working and query isn't working?
我正在使用查询搜索,但我不明白为什么一个代码是工作而另一个代码不起作用?
这是有效的:
String selectQuery = "SELECT * FROM " + TABLE_Soras
+" WHERE "+KEY_SoraName+" LIKE '%"+soraName+"%'";
Cursor cursor = db.rawQuery(selectQuery,null);
但这不会得到任何结果:
Cursor cursor = db.query(TABLE_Soras, new String[]{
KEY_SORA_NO, KEY_SoraName}, KEY_SoraName + "=?",
new String[]{soraName}, null, null, null, null);*/
因为在第二种情况下, %
没有附加到值中,并且您没有在查询中添加LIKE
子句。 你需要使用这个:
KEY_SoraName + " like ?", new String[] {"%" +soraName + "%"} ...
尝试这个
Cursor cursor = db.query(TABLE_QuranSoras, new String[]{
KEY_SORA_NO, KEY_SoraName}, KEY_SoraName+" LIKE '%"+soraName+"%'", null, null, null, null);
Cursor cursor = your_database.query(MY_TABLE, new String[] {"first_column","second_column"},your_column + " LIKE '%"+your_criteria+"%'", null, null, null, null);
尝试这样的东西,它可能会工作!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.