gpt4 book ai didi

java - SQLITE UPDATE OR INSERT 语句不想执行

转载 作者:行者123 更新时间:2023-11-30 08:13:27 24 4
gpt4 key购买 nike

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 语句)以找出错误

最佳答案

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

拆分SQL以分别执行语句。

关于java - SQLITE UPDATE OR INSERT 语句不想执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com