JDBC SQLExceptions when setAutoCommit(false)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Robert_Bamford
Posted On:   Monday, May 20, 2002 05:57 PM

When I have a Connection obtained from a connection pool (Bitmechanic's ConnectionPool connecting to Oracle 8.1.7 or to Oracle 9i) and set the autoCommit to false, what is supposed to happen in regard to the commit ing of the inserts if the connection times out (as per the parameters set in the pool instantiation) prior to completion? While I would expect the entire transaction to rollback, I have found that some of my transaction (e.g., the insertion of some of the parent records)is actually being committed, while the remainder of the transaction( e.g., insertion of the child records) is being rolled back. The entire transaction is using single connection object. This seems like very inconsistent behavior. Thoughts by anyone who has experienced t   More>>

When I have a Connection obtained from a connection pool (Bitmechanic's ConnectionPool connecting to Oracle 8.1.7 or to Oracle 9i) and set the autoCommit to false, what is supposed to happen in regard to the commit ing of the inserts if the connection times out (as per the parameters set in the pool instantiation) prior to completion?

While I would expect the entire transaction to rollback, I have found that some of my transaction (e.g., the insertion of some of the parent records)is actually being committed, while the remainder of the transaction( e.g., insertion of the child records) is being rolled back. The entire transaction is using single connection object. This seems like very inconsistent behavior. Thoughts by anyone who has experienced this???

   <<Less

Re: JDBC SQLExceptions when setAutoCommit(false)

Posted By:   Steve_Long  
Posted On:   Monday, May 20, 2002 10:04 PM

are you sending the appropriate transaction control statements to oracle, such as "set transaction" ? below is a code snippet starting a read/write transaction.


Connection cn;
PreparedStatement ps;
//
// define and create connection
//
cn.setAutoCommit(false);
cn.commit(); // clear up any pending txs
//
// next, tell the rdbms to start transaction
//
ps = cn.prepareStatement("set transaction read write");
ps.executeQuery();
//
// do sql statements
//
cn.commit(); // ends transaction
cn.setAutoCommit(true); // go back to autoCommit
//
exception (SQLException sqle) {
cn.rollback(); // if tx fails, rollback.
}
About | Sitemap | Contact