Hi,
  Are you creating the database connection in the servlets
init method and then closing it in doPost or doGet? This would 
explain your problem because the init mthod only gets called on
servlet start-up not on every request. Keeping the connection open for the
lifetime of the servlet would be reasonable performance-wise but not very fault
- tolerant. Creating and closing database connections on a per request basis is
liable to result in a serious performance hit as creating a database connection 
is typically an expensive operation  

For a robust and scaleable solution you probably want to look at database
connection pooling. Here a pool of database connections are created at start-up.
When your servlet needs to connect to the database it requests one of the
already created connections, uses it and then returns it to the pool. A 
decent implementation will balance (within set bounds) the number of database
connections available according to the needs of your application.
And if this sounds like a bit of work don't worry because some kind souls 
have already done it for you. Packages below are two commonly used 
implementations which are quite easy to integrate into your web app.

Poolman
http://www.codestudio.com/
DbConnectionBroker
http://www.javaexchange.com

Hope this helps

andrew

On Tue, 07 Aug 2001, you wrote:
> >     I have developed a servlet web application which
> > connects to a database to retrieve information.  I
> > noticed that if within my servlet I destroy the
> > connection to the database there is no way to
> > reconnect to the database .
> 
> Maybe this is a JSP thing (I'm not too familiar with those), and JSPs have
> some weird JDBC cover methods.  But you _should_ be able to disconnect, by
> calling Connection.close(); and to reconnect, the same way you connected the
> first time.
> 
> Why can't you reconnect?  Are you getting an exception from
> DriverManager.getConnection()?
> 
> >  Is keeping the persistent connection to the database
> > a heavy burden on tomcat?
> 
> Persistent connections aren't a burden on Tomcat, but might be on your
> database, especially if the modifications aren't committed immediately.  You
> should always try to close connections (and other resources) if you don't
> think you'll be using it again in a few seconds.
> 
> >   I don't believe my question pertains specifically to
> > Tomcat, so I was wondering whether or not any of you
> > knew where there are list servers which deal with
> > servlets in general.
> 
> This mailing list is fine for general servlet questions.  But this seems to
> be a JDBC question,...
> 
>                                         -- Bill K. 
> 
> > -----Original Message-----
> > From: A.L. [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, August 07, 2001 9:07 AM
> > To: [EMAIL PROTECTED]
> > Subject: Servlet/ Database Conenction Persists Question
> > 
> > 
> >     I have developed a servlet web application which
> > connects to a database to retrieve information.  I
> > noticed that if within my servlet I destroy the
> > connection to the database there is no way to
> > reconnect to the database .  In other words I need to
> > keep my connection to the database at all times that
> > tomcat is up.  My questions include:
> > 
> >  Is this correct that there is no way to reconnect to
> > the database?  If this is not correct, how does one
> > reconnect, and or reinitialize the servlet?
> >  Is keeping the persistent connection to the database
> > a heavy burden on tomcat?  In other words, is it o.k.
> > to design an application which never releases its
> > conenction to the database?
> >  
> > 
> >   I don't believe my question pertains specifically to
> > Tomcat, so I was wondering whether or not any of you
> > knew where there are list servers which deal with
> > servlets in general.
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Make international calls for as low as $.04/minute with 
> > Yahoo! Messenger
> > http://phonecard.yahoo.com/
> >


Reply via email to