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

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();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.