Reputation: 17831
In my application, the following code
ResultSet images = statement.executeQuery("SELECT id, filename, run" +
" FROM images" +
" JOIN comparer_results results ON results.toImageId = images.id" +
" WHERE result <= 100");
while (images.next()) {
statement.executeUpdate("DELETE FROM images WHERE id = "
+ images.getInt("id"));
File imageFile = new File(config.getProperty("system.imageDirectory")
+ File.separator
+ images.getString("filename") + ".jpg");
}
Throws the exception
java.sql.SQLException: Operation not allowed after ResultSet closed
In the line where the imageFile
get instantiated. It's my understanding that this is caused by the images.getString("filename")
operation. But why is the ResultSet closed? I never call such a method and the first operation on the resultset (images.getInt("id")
) works just fine.
Upvotes: 4
Views: 220
Reputation: 66243
Assoon as you called
statement.executeUpdate("DELETE FROM images WHERE id = "
+ images.getInt("id"));
you re-used the statement
. This means that any previously created ResultSet
is closed automatically.
You must use two Statement
s in this case.
Upvotes: 8