Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

autocommit - turning on after transaction is committed?

 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I turn off autocommit to perform transactions (such as two stored procedure calls involving inserts), is it necessary that I set autocommit(true) after committing?
Example code (using Sun's example, which is close to mine):

Why do I need to set the connection's autocommit back to true at the end? I was advised to do this, but logically, I've already committed the transaction... and have no need for autocommit in my apps.
(Note the connection is from a pooled Datasource)
Thanks
--
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I do agree that the statement used at the end is not required, but u may make Ur code a bit smarter thur' this:
try {
if (!con.getAutoCommit()) {
con.setAutoCommit(true);
}
}
catch (DBException dbe) {}
Try it n let me know

MSM
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't make any difference to the transaction that you have just committed, but it would make a difference to later bits of code using the same connection.
If you're using a connection pool, that's more true.
You might have a piece of code afterwards that doesn't want a transaction and doesn't bother checking that autocommit is true and so never does a commit.
 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it, thanks for the replies. I have transaction off for all my calls so far - but you never know.
---
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic