This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to find the connection object is commitable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to find the connection object is commitable" Watch "how to find the connection object is commitable" New topic
Author

how to find the connection object is commitable

Baiju Varugese
Ranch Hand

Joined: Dec 16, 2003
Posts: 74
hi all,

i done connection.setAutoCommit(false) and done some operation in my connection like select some columns and update some table after all this operations i like to know weather my connection object is commitable, ie i want to know weather i need to execute connection.commit() or connection.rollback()

thanks


Measure twice cut once carpenter theory <br /> <br />Baiju <br />SCJCP, SCBCD, IBM-486, IBM-484, SCEA Part I
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Baiju,
Whether to commit or rollback is usually a business decision. If a call threw a SQLException, you would almost certaintly want to rollback. But that would have been handled by autocommit and a transaction. Think back to why you set autocommit to false. What problem were you trying to solve?


[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
Baiju Varugese
Ranch Hand

Joined: Dec 16, 2003
Posts: 74
hi Jeanne,
Thank you. I want to do a two-phase commit for a connection, (it is already provided by JTA, reinvent the wheel). I want to write a connection manager that handles N number of connection in a transaction. i want to know all the statements in all the connection object is executed fine then i want to fire the commit on all the connection object or else i want to fire rollback. if there is any exception raised at the time of commiting i want to do the rollback on all the other connection.

thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

Baiju,
You could write a wrapper around the connection to track whether it should rollback. This object could run all queries on the user's behalf and therefore tell whether an exception occurred. Or provide a setRollbackOnly() method for callers to do this explicitly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to find the connection object is commitable
 
Similar Threads
ORA-01000: maximum open cursors exceeded
Reference to java.lang.reflect.Method
Looking for Java /MySQL /Jboss Developer 4-28-04
servlet with a worker thread
Query: