aspose file tools*
The moose likes JDBC and the fly likes connection.setAutoCommit() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connection.setAutoCommit()" Watch "connection.setAutoCommit()" New topic
Author

connection.setAutoCommit()

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
Hello all,

If I have a method which is processing bunch of SQL statements like below:

method a(){
con.setAutoCommit(false);
getA();
getB();
update();
updatex();
con.commit();

}
catch(Exception){
}
finally{
}

what are the consequences of not using the con.rollBack if some exception occurs.
Thanks,
Trupti
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by trupti nigam:

what are the consequences of not using the con.rollBack if some exception


Assume your update() method is successful and an exception occurr in updatex() method. Now if you don't rollback your transaction,the data will remain in same state changed by update() method until commit or rollaback.

If same time any other method want to perform any operation on same row changed by update() method then it will get error.

Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Annie Smith
Ranch Hand

Joined: Mar 05, 2005
Posts: 172
Originally posted by trupti nigam:
what are the consequences of not using the con.rollBack if some exception occurs.


When you are performing transaction on any database row, you are locking it and not allowing other users to perform update operations on it. A rollback() or commit() releases the locks.


Cheers!<br /><b>Annie</b>
 
 
subject: connection.setAutoCommit()