Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
---
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic