Android 无法调用 SQLite WHERE column LIKE '%?%' 该语句有 0 个参数 [英] Android fails to call SQLite WHERE column LIKE '%?%' The statement has 0 parameters
本文介绍了Android 无法调用 SQLite WHERE column LIKE '%?%' 该语句有 0 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此代码
public static List<App> findByKeyword(Context context, String keyword){
ContentResolver resolver = context.getContentResolver();
Uri uri = getContentUri();
String[] projection = DataColumns.ALL;
String selection = DataColumns.NAME+" like '%?%' ";
String[] selectionArgs = {keyword};
Cursor cursor = resolver.query(uri, projection, selection, selectionArgs, DEFAULT_ORDER );
return cursorToList(cursor);
}
出现错误
引起:java.lang.IllegalArgumentException:无法在索引 1 处绑定参数,因为索引超出范围.该语句有 0 个参数.
Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.
SQLite 原始查询应该是 SELECT * FROM table WHERE name LIKE '%?%'
但是存在通过 ContentResolver 查询 API 使用参数的问题
The SQLite raw query should be SELECT * FROM table WHERE name LIKE '%?%'
but there is problem of using parameter though ContentResolver query API
我也尝试使用 "
引号
String selection = DataColumns.NAME+" like \"%?%\" ";
它还说
该语句有 0 个参数.
The statement has 0 parameters.
推荐答案
换个角度试试:
String selection = DataColumns.NAME+" like ? ";
String[] selectionArgs = new String[]{ "%"+keyword+"%" };
希望能帮到你
这篇关于Android 无法调用 SQLite WHERE column LIKE '%?%' 该语句有 0 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文