943,603 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2442
  • Java RSS
Apr 23rd, 2008
0

SQL-JAVA ResultSet problem

Expand Post »
Hi,

I get the following exception when i try to run the following code segment.
JAVA Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
yassar is offline Offline
35 posts
since May 2005
Apr 23rd, 2008
0

Re: SQL-JAVA ResultSet problem

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.
java Syntax (Toggle Plain Text)
  1. stmt.execute( "DROP TABLE " + rs.getString(1));
Create a separate statement object to make your "DROP TABLE" calls with.
java Syntax (Toggle Plain Text)
  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();
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 838
Posting Genius
Ezzaral is offline Offline
6,756 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: null pointer exception --- urgent
Next Thread in Java Forum Timeline: Help In Java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC