android.database.sqlite.SQLiteException:near“?”:语法错误

时间:2012-07-02 09:48:24

标签: android sqlite exception cursor in-operator

Hy大家

我有一个游标,我需要在where子句中验证特定的id是否属于一个数组。

但是我有错误

android.database.sqlite.SQLiteException:near“?”:语法错误:,同时编译:SELECT display_name,_id FROM view_data_restricted data WHERE(1)AND(data1 IN?AND mimetype ='vnd.android。 cursor.item / group_membership'AND display_name like'%r%')ORDER BY display_name

这是我的代码

cursorContactosGrupos = managedQuery(ContactsContract.Data.CONTENT_URI,
                new String[]{ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME, ContactsContract.CommonDataKinds.GroupMembership._ID},
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " IN ? AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME + " like '%" + filter + "%'" ,
                new String[]{arrayTeste.toString().replace("[","(").replace("]",")")},
                ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME
                );
你能帮帮我吗? 感谢

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

cursorContactosGrupos = managedQuery(ContactsContract.Data.CONTENT_URI, new String[]{ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME, ContactsContract.CommonDataKinds.GroupMembership._ID},
                ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID + " IN (?) AND " + Data.MIMETYPE + "='" + ContactsContract.CommonDataKinds.GroupMembership.CONTENT_ITEM_TYPE + "' AND " + ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME + " like '%" + filter + "%'" ,
                new String[]{arrayTeste.toString().replace("[","(").replace("]",")")},
                ContactsContract.CommonDataKinds.GroupMembership.DISPLAY_NAME
                );

只需将?(?)

括起来

因为我们将查询写为... IN (VALUE)