tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Kientzle <>
Subject Re: Database Connectivity, JDBC2 and Tomcat
Date Fri, 28 Jul 2000 03:56:17 GMT
> "Kotsiras, Alexandros" wrote:
> In any case crerating/closing a new connection per request is almost
> "unacceptable" approach.

Hmmm...  It depends on your application.  I've been working with
a system where the (measured) run time for the servlet code is
around 0.8 seconds; opening a database connection at the 
top of doGet() and closing it at the end is only 0.1 second of
that.  Opening a connection per request is easy to code, fairly
robust against database failures (you lose only the requests being
served when the connection goes down).  As for servlet coding, it
does require you to pass the connection down into each method call.
(so you only open ONE connection per request!)

> I am using  the connection pool from with great
> success. It has a couple of examples that clearly show how to use it.

A simple connection pool is only a hundred or so lines of
pretty straightforward Java.  The big complication is if you need
to juggle multiple database accounts (different usernames and/or
different databases).  If you have one username and one database,
then you can use a straightforward Singleton to wrap the pool,
and just have every class grab a connection at the top of the
method and release it at the end.  That hides all of the database
management from the upper layers.

This is the fastest and most scalable approach in most respects,
and if you use a generic connection pool class, it will work even
with old JDBC drivers or old databases.

			- Tim

View raw message