0
我遇到問題。MySQL提交和回滾失敗
try {
jdbcConnect(); //get mysql connect
conn.setAutoCommit(false);
pstmt = conn.prepareStatement (
"INSERT INTO member (member_name, member_introduce) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
pstmt.setString(1, "something");
pstmt.setString(2, "something");
pstmt.executeUpdate();
rs = pstmt.getGeneratedKeys();
rs.next();
String no = Integer.toString(rs.getInt(1);
pstmt = conn.prepareStatement ("UPDATE account SET account_name = ? WHERE account_no = ?");
pstmt.setString(1, "something");
pstmt.setString(2, no);
pstmt.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
} catch (SQLException t) {
try {
if (conn != null) {
conn.rollback();
conn.setAutoCommit(true);
}
} catch (SQLException e) {
}
}//close conn and prepareStatement
我期待着工作提交。
但是,如果更新語句發生錯誤,插入語句正在運行。
出了什麼問題?
謝謝!! @jdevelop – blim 2012-02-12 12:49:12
現貨。這是我的問題。 – Sonny 2017-03-14 18:02:43