SQL更新语句不更改记录

时间:2012-02-23 19:14:05

标签: java sql syntax

我有一个sql update语句,但我不明白为什么它不更新我的记录,它什么都不做,语法有什么问题吗?

    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();

1 个答案:

答案 0 :(得分:2)

您应该在 dbConnection.setAutoCommit(true);之前致电executeUpdate() ,或者在dbConnection.commit(); 之后致电executeUpdate()

如果dbConnection.getAutoCommit()返回true,则表示您遇到了其他错误。你确定它没有抛出Exception吗?