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 calling getStatement().close() on a ResultSet 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 "calling getStatement().close() on a ResultSet" Watch "calling getStatement().close() on a ResultSet" New topic

calling getStatement().close() on a ResultSet

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Need some advice on this.
I have recently inherited a web application with unbelievably bad design(rather without any design at all ) . One of the problems is JSP's calling methods which open up a connection, create a statement, and then, believe it or not, return the result set to the JSP. The original programmer merrily forgot about closing the statement.
Now, of course, the best approach would be to factor away all JDBC code into java beans etc., but there are constraints on time and resources available.
One possible solution I am considering is - In each JSP page, after it is finished with the result-set, call
resultSet.close() and resultSet.getStatement().close().
One thing to note here is that the original connection used to create the statement would have been returned to the pool, and possibly new Statement objects created from it. Ugly as it is, but do you think this would work? Anything that I am overlooking here!

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

There was a thread in this forum a little while ago about problems with resultSet.getStatement().close(). It seems that the getStatement() call does not always return a valid statement.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks Jeanne.
Yeah, now that you mention it, I kinda remember that...and there was also a link to a discussion about it on a Sun forum. I'll look it up.
I agree. Here's the link:
subject: calling getStatement().close() on a ResultSet
It's not a secret anymore!