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