commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brett Porter <>
Subject RE: DBCP : some questions.
Date Wed, 29 Oct 2003 04:29:56 GMT
> For transaction support previously I was turning the 
> AutoCommit off and then the connection is put in the session 
> and forwarded to next JSP/servlet and closed the connection 
> after use. Is it the right method. Or there is any better method.

And if the next page is never requested, you leak connections. Bad idea.

You should isolate the transaction to a small period of time to avoid
locking the database. If you have potential for concurrent accesses to the
database, you will need to "dirty check" your information in the second


Request 1: get connection, select information, close connection. Pass
information to request 2.
Request 2: get connection, check information hasn't changed (can use
timestamps for this), update information with that passed from request 1,
close connection.

> In DBCP example using JNDI this code  is used to get 
> connection. Context initContext = new InitialContext(); 
> Context envContext  = (Context)initContext.lookup("java:/comp/env");
> DataSource ds = (DataSource)envContext.lookup("jdbc/Test");
> Connection conn = ds.getConnection();
> putting this code in every page,servlet and bean is not a 
> good idea(lot of typing and importing all class files). Any 
> better method for doing it.

You should abstract it into a separate class.

- Brett

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message