gpt4 book ai didi

java - JDBC -PreparedStatementexecuteUpdate() 返回 0

转载 作者:行者123 更新时间:2023-12-02 02:38:30 24 4
gpt4 key购买 nike

try{
Connection conn = getConnection();
String strUpdateQuery = "update payment_table set CREDIT_CARD_NO = ? where PAYMENT_KEY= ?";
PreparedStatement ps =conn.prepareStatement(strUpdateQuery);
for(int i=0;i<nodes.getLength();i++){
ps.setString(1,"524364OQNBQQ4291");
ps.setString(2,"20130215123757533280168");
ps.executeUpdate();
conn.commit();
}
}catch(SQLException e){
e.printStackTrace();
}

即使在我检查主键正确之后,甚至没有更新一行。

最佳答案

尝试批量更新:

void batchUpdate() {
String strUpdateQuery = "UPDATE payment_table " +
"SET CREDIT_CARD_NO = ? " +
"WHERE PAYMENT_KEY= ?";
try (Connection conn = getConnection();
PreparedStatement ps = conn.prepareStatement(strUpdateQuery)) {
for (int i = 0; i < nodes.getLength(); i++) {
ps.setString(1, "524364OQNBQQ4291");
ps.setString(2, "20130215123757533280168");
ps.addBatch();
}
int[] updated = ps.executeBatch();
// can log updated rows from "updated"
// conn.commit(); in case autocommit set to false or used conn.setAutoCommit(false) somewhere
}
catch (SQLException e) {
e.printStackTrace();
}
}

关于java - JDBC -PreparedStatementexecuteUpdate() 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45877281/

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