我有一个sql更新语句,但我不明白为什么它不更新我的记录,它什么也没做,语法有什么问题吗?
private static final String strUpdatePerson =
"UPDATE APP.PERSON " +
"SET FIRSTNAME = ?, " +
" LASTNAME = ?, " +
" ADDRESS = ?, " +
" PHONE = ?, " +
" EMAIL = ?, " +
" INFO = ? " +
"WHERE ID = ?";
这非常令人困惑,因为没有给出错误,它执行更新但没有更改数据库中的任何内容。
编辑:
这是正在执行的查询:
stmtUpdateExistingRecord = dbConnection.prepareStatement(strUpdateCustomer);
stmtUpdateExistingRecord.clearParameters();
stmtUpdateExistingRecord.setString(1, record.firstName.toUpperCase());
stmtUpdateExistingRecord.setString(2, record.lastName.toUpperCase());
stmtUpdateExistingRecord.setString(3, record.Address);
stmtUpdateExistingRecord.setString(4, record.phoneNumber);
stmtUpdateExistingRecord.setString(5, record.email);
stmtUpdateExistingRecord.setString(6, record.info);
stmtUpdateExistingRecord.setInt(7, record.getID());
stmtUpdateExistingRecord.executeUpdate();
最佳答案
您应该在executeUpdate()
或dbConnection.commit()之前调用
之后 dbConnection.setAutoCommit(true);
executeUpdate()
如果 dbConnection.getAutoCommit()
返回 true,则您将遇到不同的错误。您确定它没有抛出 Exception
吗?
关于java - SQL更新语句不改变记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9419642/