gpt4 book ai didi

Android 无法调用 SQLite WHERE column LIKE '%?%' The statement has 0 parameters

转载 作者:太空狗 更新时间:2023-10-29 16:16:22 25 4
gpt4 key购买 nike

用这段代码

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);
}

我收到错误

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 使用参数存在问题

我也试过使用 " 引号

String selection = DataColumns.NAME+" like \"%?%\" ";

它还说

The statement has 0 parameters.

最佳答案

反过来试试:

String selection = DataColumns.NAME+" like ? ";
String[] selectionArgs = new String[]{ "%"+keyword+"%" };

希望对你有帮助

关于Android 无法调用 SQLite WHERE column LIKE '%?%' The statement has 0 parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25932519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com