Hi Henrique,

On Nov 11, 2004, at 3:33 AM, Henrique Gomes wrote:


On Nov 11, 2004, at 8:00, SML wrote:

What is the 'best' way to deal with shutting down a derby db when the
data is used in jsp pages?  Do you shutdown when tomcat exits? What
happens when either the derby db or tomcat container crashes and
bypasses the shutdown script? Any problems, issues, corrections needed
on a db crash?

I generally use the Destroy() method of the servlet. Look on the docs for the way to safely shutdown a derby database.

Part of the answer depends on whether the database is going to be used for more than one application. I agree, if it's bound to a single app, then its life cycle should be bound to the servlet's.

On a related question, is it better to open/close the db connection for
different queries on different jsp pages? or to keep a persistent
connection throughout the session?

No simple answer, depends on your app.

I'd recommend in general to start out with a design that uses a connection pool to avoid creating a connection each time, and for each request, get a connection from the pool, do your work, and return the connection.

A nice way to isolate the issues is to define a filter for request processing. The init method of the filter finds or creates the connection pool. The doFilter method acquires a connection and adds it as a named attribute of the request and then calls the chained doFilter method. It gains control either normally or by catching an exception and can return the connection to the pool.

If this runs into issues, try something else, but this is the most scalable approach I know of.

Craig



Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature



Reply via email to