【问题标题】:Android Error: Too many bind arguments. 1 arguments were provided but the statement needs 0 argumentsAndroid 错误:绑定参数过多。提供了 1 个参数,但该语句需要 0 个参数
【发布时间】:2015-03-26 18:59:15
【问题描述】:

我正在点击一个按钮删除一个数据库,我的删除方法如下

 public int deleteDatabase(String tableName) {
    SQLiteDatabase db = database.getWritableDatabase();

    String whereClause = null; // delete all rows
    String[] whereArgs = { null };
    int count = db.delete(tableName, whereClause, whereArgs);
    db.close();
    return count;

}

 if (DatabaseHelper.getInstance(getApplicationContext())
                .isTableExists(MY_TABLE)) {
            Log.d(TAG, "Table exist, delete database");
            deleteDatabase(MY_LIST_TABLE);

        }

错误如下:绑定参数太多。提供了 1 个参数,但该语句需要 0 个参数。

【问题讨论】:

  • 发布 StackTrace。

标签: android sqlite


【解决方案1】:
String whereClause = null; // delete all rows
String[] whereArgs = { null };
int count = db.delete(tableName, whereClause, whereArgs);

如果您提供 whereArgs,您还必须提供有效的 where 子句(使用 ?placeholder)。像这样改变它

int count = db.delete(tableName, null, null);

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2015-06-23
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2019-04-08
    • 2018-03-23
    相关资源
    最近更新 更多