问题
使用 db.rawQuery 进行 like 查找的时候,报上面这个错误
解决
结果网上查找后发现,是因为 %
和 ?
在一起导致识别错误。正确的写法如下:
SQLiteDatabase db = analysisDBOpenHelper.getReadableDatabase();
String find = "";
Cursor cursor;
find = "SELECT " + "*" + " FROM " + "analysisInfo" + " WHERE " +
"analysisDate" + " like ?" + " AND " +
"analysisNote" + " like ?";
cursor = db.rawQuery(find, new String[]{"%" + filter[0] + "%",
"%" + filter[1] + "%"});
参考
android之Android中的SQL查询语句LIKE绑定参数问题解决办法(sqlite数据库)
https://www.cnblogs.com/lee0oo0/p/4074424.html
rawQuery()方法的使用例子
https://blog.csdn.net/zhangkongzhongyun/article/details/9084749
SQLiteDatabase之execSQL()和rawQuery()
https://blog.csdn.net/u014167212/article/details/38663825
sqlite查找包含某个字符串
https://blog.csdn.net/weixin_50690679/article/details/111211078
Sqlite数据库-使用的查询语句大全
https://blog.csdn.net/gymaisyl/article/details/108404902