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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With