tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pc leung <pingcheu...@gmail.com>
Subject Re: how to better save a trans in DBCP?
Date Wed, 07 Dec 2005 03:43:27 GMT
Will a Connection.close() close a connection
and decrease the number of connections in connection pool?



Connection con = null;
try {
 ds = (DataSource)myContext.lookup("jdbc/oracleServer");
 pooledCon = ds.getConnection("scott", "tiger");
 pooledCon.setAutoCommit(false);

 pooledCon.setTransactionIsolation(
 Connection.TRANSACTION_SERIALIZABLE);
 // ..
 pooledCon.commit();
} catch (Exception ignored) {
	try { pooledCon.rollback(); } catch (SQLException ig) {}
} finally {
	if(pooledCon != null) {

    pooledCon.setAutoCommit(true);
	  pooledCon.close();
	}
}



On 12/6/05, Varley, Roger <Roger.Varley@atosorigin.com> wrote:
> > I have classes which deal with tables individually.
> > In each class, it has the following lines to get connection pooling
> > and then commit a single table.
> >
> > Context envCtx = (Context) ctx.lookup("java:comp/env");
> > DataSource ds = (DataSource) envCtx.lookup("jdbc/myERP");
> > conn = ds.getConnection();
> > stmt = conn.prepareStatement("UPDATE ???");
> >
> > If a transaction consists of several tables,
> > how can I group them so that I can get a single connection
> > from the pool,
> > and then commit it.
> >
>
> Either create a new datasource that is session specific and returns the same connection
on each request or change your individual classes so that the datasource is passed as a parameter
so that it can be shared between multiple invocations. In either case, set up your transaction
before calling the chain of updates and call commit afterwards.
>
> Regards
> Roger
>
>
> __________________________________________________________________________
> This e-mail and the documents attached are confidential and intended
> solely for the addressee; it may also be privileged. If you receive this
> e-mail in error, please notify the sender immediately and destroy it.
> As its integrity cannot be secured on the Internet, the Atos Origin group
> liability cannot be triggered for the message content. Although the
> sender endeavours to maintain a computer virus-free network, the sender
> does not warrant that this transmission is virus-free and will not be
> liable for any damages resulting from any virus transmitted.
> __________________________________________________________________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message