File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Difference between connection.commit and usertransaction.commit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Difference between connection.commit and usertransaction.commit" Watch "Difference between connection.commit and usertransaction.commit" New topic
Author

Difference between connection.commit and usertransaction.commit

Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Hi
If I get a connection from a datasource (conn pool) then what is the difference between
(1)commit()/rollback() on the connection direction
Versus
(2) commit() /rollback() on the user transaction
Thanks
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3716
    
    5

One's a database operation, the other a user process.


My Blog: Down Home Country Coding with Scott Selikoff
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
connect.commit() is database process and usertxn.commit() is user process right? But what does this mean to the developer or to the runtime?
Given that there are two choices of doing things, which one should I pick and why?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

Babji,
They mean different things. Suppose a transaction contains multiple database connections. Committing the user transaction would commit all of them. Whereas committing the connection would only commit one.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Babji Reddy
Ranch Hand

Joined: Jan 24, 2006
Posts: 106
Thanks Jeanne,
If a transaction contains multiple database connections, then its a distributed /XA transaction right?
Lets keep it as multiple i/o operations with the same database. which can be commit/rollback either using a single usertransaction or connection.

When we use UserTransaction the transaction manager/service uses a default timeout (which if we want, we can overwrite using setTransactionTimeout method)
But if I use a connection directly (for a set of lengthy database processes) then I donot need to worry about the timeout. is this right?
If so is this the only difference?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

Babji,
Connections have inactivity timeouts. I don't recall whether they have timeouts if the connection is in use the whole time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between connection.commit and usertransaction.commit