关闭ResultSet而不关闭语句

F.P*_*F.P 2 java mysql sql jdbc

在我的应用程序中,以下代码

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");
}
Run Code Online (Sandbox Code Playgroud)

抛出异常

java.sql.SQLException: Operation not allowed after ResultSet closed
Run Code Online (Sandbox Code Playgroud)

imageFileget实例化的行中.我的理解是这是由images.getString("filename")操作引起的.但为什么ResultSet关闭了?我从来没有调用过这样的方法,对resultset(images.getInt("id"))的第一个操作就可以了.

A.H*_*.H. 6

你打电话给我

statement.executeUpdate("DELETE FROM images WHERE id = "
    + images.getInt("id"));
Run Code Online (Sandbox Code Playgroud)

你重复使用了statement.这意味着以前创建的任何内容ResultSet都会自动关闭.

Statement在这种情况下,您必须使用两个s.