File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Pool connection leak error 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 "Pool connection leak error" Watch "Pool connection leak error" New topic

Pool connection leak error

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276

In my application i am having a two classes which interacts with the database (ie creates the prepared statements & executes the query...etc.)

Now for getting the connection to the database I have made a general class called DTSConnection having a getConnection() & closePreStCon() methods which gets the connection & closes the connection respectively.

Now if do a simple connection then it works fine.
But when i am using connection pooling ,i am getting the following error:

A JDBC pool connection leak was detected.A connection leak occurs when a connection obtained from the pool was not closed explicitly by calling close() & then was disposed by the Garbage collector & returned to the connection pool.

I am providing the code templates which i have used for both the query interactor classes which is related to the connection below....

Also my actual environment where the project is to be depolyed consists of
weblogic server & unix enviroment with jdk1.3.

But my development environment consists of Tomcat 4.1 & jdk 1.4 & Windows.
In my development enviroment i am not obtaining the connections using pooling while in deployemnt environment connection pooling is used.

Both the query interactor classes are as follows:

QueryInteractor class 1

QueryInteractor 2

So please help me to sort out the error And also please tell me what is the reson behind this problem.

What i think is (just a guess )it may be due to the use of getConnection() method in both the classes.But i have closed all the connections afetr getting them...
[ June 13, 2006: Message edited by: Jignesh Gohel ]


The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Originally posted by Jignesh Gohel:
But i have closed all the connections afetr getting them...
No, you haven't. Look more closely at your createPreparedStatement method.
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi Paul thanks for the reply.

Its because after preparing the statement using createPreparedStatement() method i am immediately using either the selectQuery() or updateExecute() method & in both of them i am closing the connections.

And is it valid that we can close the connection after preparing the statement & later on use that prepared statement object after opening the connection once gain???

And please tell me what changes i will have to amke in my code..It would be a great help
I agree. Here's the link:
subject: Pool connection leak error
It's not a secret anymore!