aspose file tools
The moose likes JDBC and Relational Databases and the fly likes Problem faced while closing the ResultSet.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem faced while closing the ResultSet.." Watch "Problem faced while closing the ResultSet.." New topic

Problem faced while closing the ResultSet..

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
Error: java.sql.SQLException: ResultSet is closed

Driver Used:
1. Microsoft Access Driver
Connection con=DriverManager.getConnection("jdbcdbcRIVER={Microsoft Access Driver (*.mdb)};DBQ="+path+"","","");

here is the code
String path="C:\\Documents and Settings\\Administrator\\Desktop\\book.mdb";
Connection con=DriverManager.getConnection("jdbcdbcRIVER={Microsoft Access Driver (*.mdb)};DBQ="+path+"","","");

Statement st=con.createStatement();
String bookname="maths";
String bookid="110";
int counter=0;
ResultSet rs=st.executeQuery("select count(*) from BookMaster where bookid='"+bookid+"'");
if (counter>0)
st.executeUpdate("update BookMaster set bookname='"+bookname+"' where bookid='"+bookid+"'");
st.executeUpdate("insert into BookMaster(bookname,bookid) values ('"+bookname+"','"+bookid+"')");
catch(Exception e)
iam getting the eror at line rs.close(); i.e. while closing ResultSet.

here is the stack Trace..
java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.clearWarnings(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.close(Unknown Source)
at BookMaster.main(
When i uncomment the rs.close() it is working perfectly, can anyone give the
possible reason for it.
Allso tell how to check whether ResultSet is closed or not, before i try to close it..
thanks in advance..

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42954
I don't think you can check whether a ResultSet is is open, but closing it explicitly is unnecessary anyway. Closing the statement will automatically close the ResultSet if it is still open.
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
thanks Ulf Dittmer for the reply

can you tell me when is the resultset gets closed?
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31680

Originally posted by Abhishek Reddy Chepyala:
can you tell me when is the resultset gets closed?

Ulf just did - when the statement is closed. Similarly, if the connection gets closed (due to timeout or explicitly), the statement and result set will get closed.

[OCA 8 book] [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
Have you tried LearnNowOnline?
subject: Problem faced while closing the ResultSet..