SQLEXCEPTION Operation not allowed after ResultSet closed 错误坚持

SQLEXCEPTION Operation not allowed after ResultSet closed error insist

你好,我需要在 java.Firstly 中使用数据库执行 2 个活动作业,我用 1 个语句做了,但在我阅读这里的提示后,他们说我应该使用 2 个 statement.But,尽管它仍然可以操作ResultSet 关闭错误后不允许。

try{
        Class.forName("com.mysql.jdbc.Driver");
 }
 catch(ClassNotFoundException e){
      System.err.println("Driver yok");
        return;
 }
 Connection con=null;
    try{
     con=DriverManager.getConnection("jdbc:mysql://localhost:3306/kutuphane","root","");
     System.out.println("Veritabnı baglandıldı");
     Statement stmt=con.createStatement();       
     String strSQL="UPDATE emanetler SET IADETARIH='"+strdate+"' WHERE KISIAD='"+jTextField1.getText()+"'    "   
     Statement stmt2=con.createStatement();
     stmt.execute(strSQL);
     ResultSet rs=stmt2.executeQuery("SELECT * FROM kitaplar");      


while(rs.next()){
    if(rs.getString("KITAPAD").equals(jTextField2.getText())){
        strSQL="UPDATE kitaplar SET KITAPADET="+rs.getInt("KITAPADET")+"+1 WHERE KITAPAD='"+jTextField2.getText()+"'          ";
        stmt2.execute(strSQL);
    }    
}       
            stmt.close();
         stmt2.close();
        }
     catch(SQLException e){
         System.out.println("Veritabanı baglanmadi");
          e.printStackTrace();
     }

首先你使用的是stmt2对象

ResultSet rs=stmt2.executeQuery("SELECT * FROM kitaplar");

然后在while循环中

strSQL="UPDATE kitaplar SET KITAPADET="+rs.getInt("KITAPADET")+"+1 WHERE KITAPAD='"+jTextField2.getText()+"'          ";
stmt2.execute(strSQL);

必须更正此问题以在 While 循环中使用单独的语句对象来执行查询。

希望对您有所帮助