The moose likes JDBC and Relational Databases 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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connection.SetAutoCommit" Watch "connection.SetAutoCommit" New topic


Kash Mhai

Joined: Apr 01, 2005
Posts: 29
Hi All,
Please see the following code..
//con=getConnection();//Assume connection is there..
//Insert some rows into a table
//All succeded.. no problems
catch (Exception e){
My questions are -
1. Does the AutoCommit property of the connection need to be set to TRUE?? before the connection is closed?
2. Does the rollback() need to be commited? I mean,
after using con.rollback(); in catch, do we need to use con.commit() again?
3. If i dont set the connection to setAutoCommit(true) again, will there be an effect while managing data from backend?
4. Does not using con.commit() after con.rollback(), and not setting the AutoCommit to true cause any performance issues?


-------------<br />There are wheels within wheels...<br />P.G Wodehouse
Ann Sebastian
Ranch Hand

Joined: Sep 21, 2005
Posts: 37
1.By specifying conn.rollback() rolls back the transaction.You dont need to use conn.commit() after rollback to commit rollback.
2.conn.setAutoCommit has to be set to true if you dont want to explicitly commit other transaction from java.I dont think it affects performance in backend.
I agree. Here's the link:
subject: connection.SetAutoCommit
It's not a secret anymore!