0

I have this error in my code and have checked and edited it thoroughly, yet I still get same issue. I also use multiple resultSet and Statements yet same error occurs. Below is the error I get:

    "Database Connected with Current Date 20130221
    java.sql.SQLException: ResultSet is closed
    at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcResultSet.next(Unknown Source)
    at UNSUB.main(UNSUB.java:78)"
Press any key to continue . . .

Please What could be the reason? I have no idea on any solution now.

Imaxo
  • 11
  • 1
  • 4

2 Answers2

5

The exception, java.sql.SQLException: ResultSet is closed means that your code has either already closed the result set object you're using, or more likely, that your code has either re-executed or closed the statement that produced the result set. By JDBC specs, either of those actions will close any result set from the statement.

Rahul
  • 44,383
  • 11
  • 84
  • 103
  • thanks for your reply. In the code I have a nested resultSet with a different statement yet error occurs. – Imaxo Feb 21 '13 at 10:22
  • 1
    share the code, which will help in pointing out the exact erroneous block. – Rahul Feb 21 '13 at 10:25
  • `rs1 = stmt2.executeQuery("select cnt from t1 where num = '"+ str2 +"'"); rs1.next(); cnt = rs1.getInt("cnt"); if(cnt > 0) { rs2 = stmt3.executeQuery("select * from t1 where num = '123"); while (rs2.next()) { reg_date = rs2.getString("reg"); ins1 = stmt3.executeUpdate("INSERT INTO t2 ([num]) VALUES('"+ str2 +"')"); Thread.sleep(10); ins2 = stmt3.executeUpdate("delete from t1 where num = '"+ str2 +"'); } }` – Imaxo Feb 21 '13 at 10:58
-2

Have you called the method next() on the ResultSet?? If you haven't that might be the reason for you to get that error.

Aashray
  • 2,753
  • 16
  • 22
  • Yes I called the .next() method and changed the statement name. I would be willing to share code if needed. thanks – Imaxo Feb 21 '13 at 10:21
  • The stacktrace in the question clearly shows that `next()` has been called – Mark Rotteveel Feb 21 '13 at 10:32
  • didn't notice the next() method being called. – Aashray Feb 21 '13 at 11:12
  • You seem to keep forgetting to close single quotes. While executing stmt3, u have missed `'` at the end and while executing the delete statement, u have missed a double quotes. Check those and let me know if it works. – Aashray Feb 21 '13 at 11:21
  • Oh! sorry about that. It is a typo error when editing in the message box. That is not the problem I am having. My code compiles and runs but later throws an exception(while running). Thanks – Imaxo Feb 21 '13 at 11:43
  • It still gives me same error. pls what other issue can cause this error? I am stocked – Imaxo Feb 21 '13 at 13:11