gpt4 book ai didi

java - SQL更新语句不改变记录

转载 作者:行者123 更新时间:2023-12-02 07:57:28 25 4
gpt4 key购买 nike

我有一个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/

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