Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

connection.setAutoCommit()

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Annie Smith
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic