0

Hi,

I get the following exception when i try to run the following code segment.

stmt = (Statement) conn.createStatement();
			
rs = stmt.executeQuery( "SHOW TABLES");
						
if(rs.first()) {
	stmt.execute( "DROP TABLE " + rs.getString(1));
	while (rs.next()){
		stmt.execute( "DROP TABLE " + rs.getString(1));
	}
}

And the exception i get is:
SQLException: Operation not allowed after ResultSet closed
SQLState: S1000
VendorError: 0

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ezzaral
0

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.

stmt.execute( "DROP TABLE " + rs.getString(1));

Create a separate statement object to make your "DROP TABLE" calls with.

PreparedStatement updateStmt = conn.prepareStatement("DROP TABLE ?");

stmt = conn.createStatement();
			
rs = stmt.executeQuery( "SHOW TABLES");
						
while (rs.next()) {
    updateStmt.setString(1, rs.getString(1));
    updateStmt.executeUpdate();
}
updateStmt.close();
stmt.close();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.