标题:Operation not allowed after ResultSet closed
取消只看楼主
jackflyer
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2016-11-19
结帖率:57.14%
 问题点数:0 回复次数:1 
Operation not allowed after ResultSet closed
public class shanchuB  implements ActionListener{

    JTextField t;
    public shanchuB(JTextField t) {
        this.t=t;
    }
   
    public void actionPerformed(ActionEvent e) {
        String shnumber=t.getText();
        
        if(shnumber.equals(""))
              JOptionPane.showMessageDialog(null, "请填写学号!");
        else {
            
                    //定义mysql数据库驱动的类mysql.jdbc.Driver
                    String driverClass1="com.mysql.jdbc.Driver";
                    //定义连的mysql的URL接
                    String url1="jdbc:mysql://localhost:3306/grade";
               
                    String username11="root";
                    //密码
                    String password11="2827391563";
                    //定义Connection连接
                    Connection conn1=null;
                    
                    Statement stmt1=null;
                    
                    try {
                        //注册数据库的驱动程序
                        Class.forName(driverClass1);
                      conn1 =  DriverManager.getConnection(url1,username11,password11);
                      stmt1 = conn1.createStatement();
                      String sql1="SELECT * FROM managedata.student;";
                      String  sql2="DELETE FROM `managedata`.`student` WHERE studentnumber='"+shnumber+"'";  
                      ResultSet rs1=stmt1.executeQuery(sql1);
            
                  
                      while(rs1.next()){  
                          String tnumber=rs1.getString("studentnumber");
                          if(tnumber.equals(shnumber)) {
                         stmt1.executeUpdate(sql2);
                              
                              JOptionPane.showMessageDialog(null, "删除成功!");
                          }
                              
                      }} catch (Exception e1) {
                    
                        e1.printStackTrace();
                    }finally {
                        try {
                            if(stmt1!=null) {
                        stmt1.close();
                            }
                            if(conn1!=null)
                            {
                                conn1.close();
                            }
                        }catch(Exception e1) {
                            e1.printStackTrace();
                        }
                    }

                    }
        }

    }
    怎么解决。求大神指教,谢谢!
搜索更多相关主题的帖子: closed public 数据库 mysql null 
2017-05-10 20:47
jackflyer
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2016-11-19
得分:0 
我已经解决,谢谢大家
2017-05-11 20:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-476902-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.737398 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved