francan00@yahoo.com wrote:
>> I would like to create a single Database connection point that I can
>> use for 4 classes in my Java Web Application.
> Before spending more time on this problem: redesign, because
> a static connection used in a web app is not good. It is not
> thread safe and web apps are multi threaded.
Furthermore, most JDBC drivers include a pooled-connection type, at least a
rudimentary one, and Apache has pooling libraries that seem pretty workable.
Push that connection-pooling layer as far to the back as it will go. Your
bizlogic should use and close connections as tightly as possible. The pooling
driver will convert "close" into "recycle" for you.
Holding connections open in the wrong place is a scalability killer.

Signature
Lew
RedGrittyBrick - 18 Oct 2007 11:36 GMT
> Furthermore, most JDBC drivers include a pooled-connection type, at
> least a rudimentary one, and Apache has pooling libraries that seem
> pretty workable. Push that connection-pooling layer as far to the back
> as it will go. Your bizlogic should use and close connections as
> tightly as possible. The pooling driver will convert "close" into
> "recycle" for you.
Some URLs that might be helpful:
http://www.java2s.com/Code/Java/Apache-Common/ConnectionPoolBasics.htm
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/conpool.html
When I first started with a JDBC app, having read that connections were
expensive, I tried to use a single connection and manage it's re-use
myself. Eventually I had to rework the app to use a pool of connections
(I used the code from the second URL above). Later, in order to minimise
the duration of locks, I had to rework my app to minimise the work done
between obtaining a connection and closing it (releasing it back to the
pool). Which is a long way of saying that Lew's recommendations make a
lot of sense, thinking about this now may save time later.