try {
connection.setAutoCommit(false);
bankDao.transferMoney(+2000, 1, connection); //1 2000
if(true){
throw new RuntimeException(); //
}
bankDao.transferMoney(-2000, 2, connection);//2 2000
connection.commit();
} catch (Exception e) {
try {
connection.rollback();
System.out.println("");
} catch (Exception e1) {
e1.printStackTrace();
}
}
I find that even if I don"t use connection.rollback ()
, the data in the database will not change because the transaction has not been committed, even if I use it or not, so why should I use connection.rollback ()
? Thank you