tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikola Milutinovic" <Nikola.Milutino...@ev.co.yu>
Subject Re: [OT] JDBC confusion
Date Thu, 07 Aug 2003 09:03:12 GMT
> Hello List... newbie question coming up:

Phaser charged...
Shields at 80%...
Photon torpedos loaded...

> If I set up a jdbc connection object in one servlet, do I have to close it each time
> or can the same connection be re-utilized by other servlets each using a different
> sql statement (perhaps storing the connection as a session attribute?).

This might give you a speed boost, since openning a connection can be time consuming. But
that is the main idea behind JDBC connection pooling, so why re-invent the wheel? Poorly,
I might add.

> Is there a significant resource saving by not creating a JDBC connection object for each
database access?

That depends on a particular JDBC driver, but usually no. You'll most likely save time.

> I'm thinking of storing a connection for each user in the session, as opposed to pooling
> - primarily because I'm not sure how a database pool works nor how to set it up.

A JDBC connection pool does what you want and more. It opens several connections and keeps
them ready and waiting in the connection pool. The minimum and maximum number of connections
are usually configurable (at least with DBCP in Tomcat). Physical maintainance of connections
(checking if it is OK) is also implemented in DBCP. So, why don't you save yourself a lot
of trouble and use JDBC connection pool over JNDI, as described in Tomcat docs?

I had it working with Tomcat 2.1.24 and PostgreSQL 7.3.2. It also couples nicely with JSTL's
"sql" tags.

> Should I do a re-think on this?

Most definitely.

> I'm using one postgresql 7.3.3

Switching to 7.3.4 is recomended - there is a critical startup bug introduced in 7.3.3.

Nix.
Mime
View raw message