wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes JDBC and Open Data Paths 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 and Open Data Paths" Watch "JDBC and Open Data Paths" New topic

JDBC and Open Data Paths

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Hi. I have a question regarding JDBC and Open Data Paths (I'm using iSeries DB2 V5R2). I've been looking at some of our users' jobs that are using a java application of ours, and some of them have 200+ open data paths, which a lot of them are on the same tables.
Am I doing something wrong here? Why wouldn't the same open data path be opened if was opened once before.
Is it the way I am closing my statement/result set objects?
I was told once that all I had to do, was just close the statement object once the query was done, becuase it would automatically close the ResultSet object with it. But I have seen where other people are closing the ResultSet and the Statement object.
If I were to close the ResultSet first and then the Statement object, would this help with the number of open data paths.
Sorry if this is a really lame question, but I don't have a whole lot of experience with JDBC stuff, and how everything works in the background.
Any help is appreciated.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
From what I've read and experienced, it's best to explicitly close the ResultSet and then the Statement. These should be done within the "finally { }" clause of a try/catch block to ensure that it happens regardless of whether the execution worked or failed. I'll see if I can back this up with a link to something more definitive.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Here's a link to Oracle JDBC documentation. To quote under the heading Closing the Result Set and Statement Objects (Under (3) Basic Features --> First Steps in JDBC):

You must explicitly close the ResultSet and Statement objects after you finish using them. This applies to all ResultSet and Statement objects you create when using the Oracle JDBC Drivers. ... If you do not explicitly close your ResultSet and Statement objects, serious memory leaks could ocur. You could also run out of cursors in the database.

Unfortunately it may vary from database to database, depending on the JDBC drivers. But it can't hurt to close those ResultSet instances and see what happens ...
[ October 31, 2003: Message edited by: Wayne L Johnson ]
subject: JDBC and Open Data Paths
It's not a secret anymore!