This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes whats the use of closing ResultSet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "whats the use of closing ResultSet ?" Watch "whats the use of closing ResultSet ?" New topic
Author

whats the use of closing ResultSet ?

Shilpa Nagaraj
Greenhorn

Joined: Apr 11, 2007
Posts: 4
when we close a connection to database with out closing resultset it gives out an error stating that resultset is already closed . So when we are not able to access resultset after closing connection to database , is it necessary to close resultset?
Prabhu Sathya
Greenhorn

Joined: Jul 13, 2006
Posts: 8
Hope you find this article useful :


Many books about JDBC and most of JDBC-related sample code floating around seems to assume that JDBC is used directly, meaning that database connection is established by the DriverManager, and is actually released when myJDBCConnection.close() method is called. In this case, all resources associated with this database connection, such as ResultSet and Statement objects (and whatever is used on the database side to implement them), are released as well.

There is a problem with this approach. When moving to ´┐ŻEnterprise´┐Ż-type applications, most JDBC connections are obtained from connection pools. When myConnection.close() is invoked on such a connection, it is not actually released. It is returned back to the connection pool to be re-used by other objects. In this case, all database resources associated with the connection may not be released. Thus, database cursors and other database-specific objects that are used to implement ResultSets and Statements are not freed.

This may result in applications running out of database resources, even though the JDBC connections themselves are properly closed.

The way to work around this issue is to close ResultSet and various Statement objects as soon as the code is done using them, or in the finally{} block.
Shilpa Nagaraj
Greenhorn

Joined: Apr 11, 2007
Posts: 4
Thanks for the reply
 
 
subject: whats the use of closing ResultSet ?
 
Similar Threads
open Resultset and closed connection
Is connection.close(); enough?
Result set not showing the latest data
Closing connection
ResultSet after DB closed