connection pool and transaction for the few connections from pool
From: PYCTAM (rbogubaev_at_bookinturkey.com)
Date: 12/15/04
- Next message: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Previous message: Virgil Green: "Re: Hanging SQL query (Oracle)"
- Next in thread: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Reply: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 14 Dec 2004 15:10:28 -0800
hi,
I would like to know whether possible or not to make a transaction
using db connection pool.
I have db connection pool to MS SQL 2000 using Tomcat 5.0's JDBC
DataSource (see on :
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html#Database%20Connection%20Pool%20(DBCP)%20Configurations)
Below is simple example code which I have. So I need to rollback all
data including inserted country and region records to db in case of
exception. Is it possible or not and how it is possible?
public void methodWithTransaction(){
Connection c = null;
Country ctr = new Country();
Region rgn = new Region();
try{
c = Session.getPooledConnection(); // Get connection from pool
c.setAutoCommit(false); // Open transaction
rgn.setCode("CH");
rgn.setName("CHUY");
rgn.doInsert(); // In this method was used
// another connection
// from pool
ctr.setCode("KG");
ctr.setName("Kyrgyzstan");
ctr.setRegion(rgn);
ctr.doInsert(); // In this method was used
// another connection
// from pool too.
//
// IMPORTANT QUESTION HERE !!!
//
// --> So we have used 3 connections
// --> from the pool but transaction
// --> was set only to connection within
// --> this method. What will happen
// --> in case of exception?
// --> Will be inserted country and
// --> region records rolled back?
//
}catch(Exception e){
if (!c.getAutoCommit()){
c.rollback();
c.setAutoCommit(true);
}
}finally{
if (!c.getAutoCommit()){
c.commit();
c.setAutoCommit(true);
}
try{
if (c != null){
c.close();
}
}catch(Exception e){
// do something
}finally{
rgn = null;
ctr = null;
c = null;
}
}
}
sincerely,
rustam bogubaev
- Next message: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Previous message: Virgil Green: "Re: Hanging SQL query (Oracle)"
- Next in thread: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Reply: Joe Weinstein: "Re: connection pool and transaction for the few connections from pool"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|