【问题标题】:SQLITE UPDATE OR INSERT statement doesn't want to executeSQLITE UPDATE OR INSERT 语句不想执行
【发布时间】:2015-05-03 13:29:36
【问题描述】:
public synchronized void saveMatchValue(int photoRecOwner,
        int[] photoRecAssign, float[] value) {
    SQLiteDatabase database = databaseHelper.getWritableDatabase();
    database.beginTransaction();
    String sql = " UPDATE " + TypeContract.CTablePhotoMatch.TABLE_NAME
            + " SET " + TypeContract.CTablePhotoMatch.VALUE + "=? "
            + " WHERE " + TypeContract.CTablePhotoMatch.FK_OWNER
            + "=? AND " + TypeContract.CTablePhotoMatch.FK_ASSIGN + "=? ;"
            + " INSERT OR IGNORE INTO "
            + TypeContract.CTablePhotoMatch.TABLE_NAME + "("
            + TypeContract.CTablePhotoMatch.FK_OWNER + ","
            + TypeContract.CTablePhotoMatch.FK_ASSIGN + ","
            + TypeContract.CTablePhotoMatch.VALUE + ") VALUES (?, ?, ?);";

    SQLiteStatement stmt = database.compileStatement(sql);

    try {

        int rows = photoRecAssign.length;
        for (int i = 0; i < rows; i++) {

            if (photoRecOwner > photoRecAssign[i]) {
                stmt.bindLong(1, photoRecOwner);
                // stmt.bindLong(index, value)
                stmt.bindLong(2, photoRecAssign[i]);

            } else {
                stmt.bindLong(1, photoRecAssign[i]);
                stmt.bindLong(2, photoRecOwner);

            }
            stmt.bindDouble(3, value[i]);

            stmt.execute();
            stmt.clearBindings();

        }
        database.setTransactionSuccessful();
    } finally {
        stmt.close();
        // updtStmt.close();
        database.endTransaction();
        // database.close();
    }
}

没有错误和编译错误,

我不知道sql语句语法是否正确:具体的:; ,但没有编译错误,插入和(可能是更新)命令不会执行.... 我可以捕捉更多细节吗?(关于sqlite语句)找出错误

【问题讨论】:

  • 你为什么使用bindDouble

标签: java sqlite sql-update


【解决方案1】:

您只能使用SQLiteStatement 执行单个语句。 ;后面的SQL没有执行。

拆分 SQL 以分别执行语句。

【讨论】:

  • 是的,那是我最初的解决方案,但它的版本非常好……我需要一些快速的解决方案
猜你喜欢
  • 2011-06-11
  • 2015-05-10
  • 2017-07-30
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 2019-11-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多