tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From QM <>
Subject Re: connection pooling basic help please
Date Sat, 02 Apr 2005 21:44:23 GMT
On Sat, Apr 02, 2005 at 08:21:24PM +0100, Krishnakant Mane wrote:
: the example in tomcat documentation is on a jsp based
: applicatio.  but I don't understand how I use a pooled
: connection in a servlet.
: [snip]
: should I initialise the connection in the Init method?
:  how and when should I close the connection?

1/ please post a *new* message when writing to the list.  Replying to
an old (unrelated) message confuses thread-aware mailers, which makes
your question harder to find (and thus answer).

2/ I don't have the JSP sample in front of me, but there should be
plenty of examples of using a DataSource out on the web.  A little
Googling should turn them up.  The short version is:
 - perform a JNDI lookup to find the DataSource
 - pull a Connection from that data source
 - use the Connection to talk with a databse
 - call close() on that connection

You should hold on to the Connection for as short a period of time as
possible.  This is easier to manage if all of the database calls are
done from a particular set of objects (a data layer).

Having all of your components do the JNDI lookup, etc can get messy and
tough to maintain.  Isolate all of your data calls to a separate object
(or set of objects).  You could initialize these objects in a
ServletContextListener and either store them under Application scope or
in a singleton such that they would be globally available.


software   --
tech news  --
code scan  --

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message