Hi,
You might want to get a book on good Java design practices.  The basic
ideas are there:
- Hold the connection for as little a time as possible.  That is, get it
from the pool, use it, and return it to the pool as soon as possible.
- That means you don't get the connection in a servlet init() method and
return it in a destroy() method.  That's too long a time to hold
connections usually.
- Always return connections to the pool.  Typically, this is done in the
finally clause of a try/catch block to ensure it is executed even if the
JDBC operation fails.
- You create your pool once, preferably when the app starts up, and you
close the pool itself once, preferably when the app shuts down.  A
ServletContextListener is good for this purpose.  Make sure you close
the pool.
- Servlets and other classes use the pool as needed.  You don't have to
use a one connection per servlet design (in fact those usually don't
work in the real world).

In the future, please mark non-Tomcat questions with [OFF-TOPIC] in the
subject line.  And again, consider getting a Java design practices book:
practically all of them have a chapter on JDBC connection pooling with
the above suggestions.

Yoav Shapira
Millennium Research Informatics


>-----Original Message-----
>From: Michael McQuade [mailto:[EMAIL PROTECTED]
>Sent: Tuesday, September 07, 2004 9:06 PM
>To: Tomcat Users List
>Subject: Some pretty basic Tomcat Connection Pooling Questions????
>
>Sorry folks,   this is a REAL Newbie to Tomcat/Java.....  Im trying to
>understand Connection Pooling as it seems I will need this in my
webapp....
>Please dont laugh too hard at me ok....
>
>When doing connection Pooling,    do you do an Open and close of your
>database for every Java class (servlet) you execute?
>
>Or
>
>Do you do a one time Open of your database at the first login?
>
>Or
>
>Do you just do an Open Database and NOT a CLOSE database for each Java
>Class (servlet)?
>
>I know this sounds stupid,   but Im currently NOT using Connection
Pooling,
>and when I  go into my first Java class (servlet),  I can OPEN/UPDATE
all
>successfully,   but when I do a Disconnect I get an SQLSTATE = 08003
>(connection does not exist)
>I then try and go into my next Java Class  (servlet) and right away,
on
>my OPEN, I get SQLSTATE = 08002 (connection name in use)
>
>It will never allow to access my database again, I have to go back to
>Application Manager,  Stop and then Start the application,   go back
into
>it,  and I get my one connection again,  but just the one.....
>
>Thanks Mike



This e-mail, including any attachments, is a confidential business communication, and 
may contain information that is confidential, proprietary and/or privileged.  This 
e-mail is intended only for the individual(s) to whom it is addressed, and may not be 
saved, copied, printed, disclosed or used by anyone else.  If you are not the(an) 
intended recipient, please immediately delete this e-mail from your computer system 
and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to