Meaningless Drivel is fun!*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "calling getStatement().close() on a ResultSet" Watch "calling getStatement().close() on a ResultSet" New topic
Author

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!
thanks


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Sonny,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: calling getStatement().close() on a ResultSet
 
Similar Threads
UltraDev JSP Help
Problem with "Try" blocks and variables - JDBC 2a
A connection taken from Statement != used for creation it at pooling
JDBC Program Design Question
OutOfMemoryError caused by PreparedStatements held in Connection