• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Connection Leakage: Closing Connection BEFORE Closing Statement?

 
Bob Hager
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an application that connects to a Microsoft SQL Server 2005, using a JDBC connection pool accessible via a datasource.

I am suspecting a connection leakage problem, since the established connections count (between the application server and the database server) keeps on rising until everything freezes up and we have to restart the application server.

I suspect the problem to be in the following code:

Please note that the developer who wrote this, tries to close the cstmt (CallableStatement) AFTER the conn (Connection) is closed.

I'd appreciate some opinions on this, do you think the order of closing the connection is responsible for the leakage? Also, what about the case when the developer forgets to close the cstmt in the first place, could that account for a connection leakage? What about failing to close a ResultSet?

I appreciate any insights or tips towards debugging this problem, and towards better understating JDBC clean-ups in general.

Bob
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,
It's hard to say as it depends on the JDBC driver. If the driver followed the specification, closing the connection would close the statement and the second line would either do nothing silently or throw an exception. If the driver didn't follow the specification, anything could happen.



The best way to find out whether this causes a connection is to run it in a tight loop on your machine 100 times and see what happens. What really matters is what happens with your driver since your system is the one with the connection leak.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic