android- 数据库 模糊搜索, 单引号 ’ 报错问题(SQLiteException: unrecognized token: “‘)
cursor = MainActivity.this.getContentResolver().query(uri, new String[]{"display1"}, "display1"+" like" +" '%"+tempSearchContent+"%'", null, "date desc");
这样进行模糊搜索,如果tempSearchContent 为 ‘(单引号),需要对 其进行转义
或者 使用selectionArgs 参数:
String like = "%" + tempSearchContent + "%";
cursor = MainActivity.this.getContentResolver().query(uri, new String[]{"display1"}, "display1 like?", new String[]{like}, "date desc");
本文介绍了一种解决在Android应用中使用SQLite进行数据库模糊搜索时遇到的单引号(’)导致的错误(unrecognized token:‘)的方法。通过转义特殊字符或使用selectionArgs参数来避免SQL语法错误。
1万+





