autocommit - turning on after transaction is committed?
Toby Davis
Ranch Hand
Joined: Apr 09, 2002
Posts: 65
posted
0
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
Joined: Jun 25, 2001
Posts: 110
posted
0
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
Joined: Oct 09, 2001
Posts: 564
posted
0
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.
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Toby Davis
Ranch Hand
Joined: Apr 09, 2002
Posts: 65
posted
0
Got it, thanks for the replies. I have transaction off for all my calls so far - but you never know. ---
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: autocommit - turning on after transaction is committed?