报错原文
java.lang.IllegalArgumentException: Too many bind arguments. 3 arguments were provided but the statement needs 1 arguments.
java.lang.IollegalArgumentException:绑定参数太多。提供了3个参数,但该语句需要1个参数。
错误写法
db.delete(TABLE_NAME, "photoName = ?", new String[]{"1704266280292.jpg","1704265939215.jpg","1704274780297.jpg"});
错误原因
在于delete()的第三个参数只能填一个参数,如果想删多个参数要这样写
正确写法
String[] fileNames = new String[]{"1704266280292.jpg","1704265939215.jpg","1704274780297.jpg"};
String sqlDelete = "DELETE FROM "+aabc_table+" WHERE photoName IN (";
for(int i=0; i<fileNames.length-1; i++) {
sqlDelete += "'" + fileNames[i] + "', ";
}
sqlDelete += "'" + fileNames[fileNames.length-1] + "')";
try {
db.execSQL(sql);
Log.d("wangrui","删除成功!");
}catch (Exception e){
Log.d("wangrui","删除异常失败");
}
sqlDelete 值如下:
DELETE FROM aabc_table WHERE photoName IN ('1704266280292.jpg', '1704265939215.jpg', '1704274780297.jpg')