SQL-JAVA ResultSet problem

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 30
Reputation: yassar is an unknown quantity at this point 
Solved Threads: 0
yassar's Avatar
yassar yassar is offline Offline
Light Poster

SQL-JAVA ResultSet problem

 
0
  #1
Apr 23rd, 2008
Hi,

I get the following exception when i try to run the following code segment.
  1. stmt = (Statement) conn.createStatement();
  2.  
  3. rs = stmt.executeQuery( "SHOW TABLES");
  4.  
  5. if(rs.first()) {
  6. stmt.execute( "DROP TABLE " + rs.getString(1));
  7. while (rs.next()){
  8. stmt.execute( "DROP TABLE " + rs.getString(1));
  9. }
  10. }

And the exception i get is:
SQLException: Operation not allowed after ResultSet closed
SQLState: S1000
VendorError: 0
Last edited by yassar; Apr 23rd, 2008 at 4:45 am.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,514
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 523
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: SQL-JAVA ResultSet problem

 
0
  #2
Apr 23rd, 2008
You have executed a new query here through your statement so the result set you obtained with that statement is no longer valid and you cannot retrieve field values from it.
  1. stmt.execute( "DROP TABLE " + rs.getString(1));
Create a separate statement object to make your "DROP TABLE" calls with.
  1. PreparedStatement updateStmt = conn.prepareStatement("DROP TABLE ?");
  2.  
  3. stmt = conn.createStatement();
  4.  
  5. rs = stmt.executeQuery( "SHOW TABLES");
  6.  
  7. while (rs.next()) {
  8. updateStmt.setString(1, rs.getString(1));
  9. updateStmt.executeUpdate();
  10. }
  11. updateStmt.close();
  12. stmt.close();
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1688 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC