请告诉我什么情况下需要调用connection.rollback()方法。
在上述代码中,我们没有使用connection.rollback()方法,但即使发生异常,一切也将正常工作[我猜],因为连接已经设置为自动提交=false模式。
那么什么情况下我们需要使用这个方法呢?请附带示例。
try{
connection = getConnection();
connection.setAutoCommit(false);
pstmt1 = connection.preparedstatement ( ... );
...
pstt1.executeUpdate();
pstmt2 = connection.preparedstatement ( ... );
...
pstt2.executeUpdate();
connection.commit();
}catch ( Exception sqe ) { sqe.printStacktrace();
}finally {
closeQuitely ( pstmt1 );
closeQuitely ( pstmt2 );
closeQuitely ( connection );
}
在上述代码中,我们没有使用connection.rollback()方法,但即使发生异常,一切也将正常工作[我猜],因为连接已经设置为自动提交=false模式。
那么什么情况下我们需要使用这个方法呢?请附带示例。