954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQL-JAVA ResultSet problem

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:[INDENT]SQLException: Operation not allowed after ResultSet closed
SQLState: S1000
VendorError: 0
[/INDENT]

yassar
Light Poster
35 posts since May 2005
Reputation Points: 10
Solved Threads: 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();
Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You