• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

autocommit - turning on after transaction is committed?

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
--
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
---
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic