The moose likes JDBC and Relational Databases and the fly likes jdbc database connection (not being closed) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc database connection (not being closed)" Watch "jdbc database connection (not being closed)" New topic

jdbc database connection (not being closed)

Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

I am working on a legacy web application that issues jdbc commands from jsps. The jdbc database connection is issued once in the beginning from some java initialization code.

After awhile, the database access gets very slow. I fear that the connection is never closed when the user logs out or an exception is thrown. Where should I close the database connection without using connection pooling?

If I have to use connection pooling, what product would you recommend?

Thanks for your help and time.


Wendy Gibbons

Joined: Oct 21, 2008
Posts: 1107

so let me check what you are saying.
The database connection is opened when the webapp is started and the same connection is used all the time until the webapp is shut down?
Or is it just once per session?

so i bet whoever designed this didn't think to close any statement or result sets.

Finding and closing every statement, prepared statement and result set in a finally block, would be the very first thing to do.

and close the connection whenever it is finished with would be the second job.
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104

The connection is obtained when the webapp comes up and stored in the servletContext.

Most of the statements have been closed (I closed the the ones that weren't)...none of the resultsets have been closed. The same ResultSet object is used for a given jsp.

Since the same connection is used for all clients, would you recommend using a connection pool?


I agree. Here's the link:
subject: jdbc database connection (not being closed)
It's not a secret anymore!