我正在尝试批量删除表中的某些项目。
String ids = { "1", "2", "3" };
mContentResolver.delete(uri, MyTables._ID + "=?", ids);
但是我不断收到以下错误
java.lang.IllegalArgumentException:绑定参数太多。提供了 3 个参数,但该语句需要 1 个参数。
您可以使用内容提供者操作用于在一个事务中批量删除/插入/更新。更好的是您不必连接字符串。它也应该非常有效。对于删除:
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
ContentProviderOperation operation;
for (Item item : items) {
operation = ContentProviderOperation
.newDelete(ItemsColumns.CONTENT_URI)
.withSelection(ItemsColumns.UID + " = ?", new String[]{item.getUid()})
.build();
operations.add(operation);
}
try {
contentResolver.applyBatch(Contract.AUTHORITY, operations);
} catch (RemoteException e) {
} catch (OperationApplicationException e) {
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)