rollback Method
rollback Method
transaction. The call to the rollback method of UserTransaction undoes the effects of all
statements in the transaction so as to protect the integrity of the data.
@Resource
UserTransaction utx;
...
try {
utx.begin();
bookDBAO.buyBooks(cart);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception exe) {
System.out.println(
"Rollback failed: "+exe.getMessage());
}
...
Accessing Databases from Web Applications
The Java EE 5 Tutorial · September 2007
710