• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update inside Select statement

 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am trying to select rows from table and copy it in another table and update the first table rows status but i am facing issues in this



but here i am getting error

java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(Unknown Source)

Can anybody suggets me whats wrong here?
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It simply means that your resultset has been closed. Your code looks ok. Can you check if you have written rs.close() or ars.close() any where in your code ?
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ruquia tabassum wrote:


First, Make sure where exactly you are getting the error. There are two ResultSets involved here (rs & ars). May be you have closed the "ars" already?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems an odd way to do this. Why issue individual update statements as you iterate through your result set rather then one after you have iterated through your result set? What you are doing has a lot of unecessary database round trips. e.g.




 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have only one result set object and that is rs and i did not specify rs.close() anywhere in my code my complete program is



error:
id 7 name survey

java.sql.SQLException: ResultSet is closed
at sun.jdbc.odbc.JdbcOdbcResultSet.checkOpen(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcResultSet.next(Unknown Source)


If there are unnecessary round trips then the output should be slow but here i am getting an odd message saying ResultSet closed and the while loop is not iterating through all the records fetched it just shows one record from the System.out.println ("id"+id+"name"+name).
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Updating a result set as you iterate through it would usually be done with an updatable results set, which is not somthing Access supports. I wouldn't be surprised if your update is also causing the result set to be closed.


i did not specify rs.close() anywhere in my code my complete program is
]
This is very bad practice. You should always release JDBC resources in a finally block.
 
carina caoor
Ranch Hand
Posts: 300
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i could solve it by using different statement for insert , select and update

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic