| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1866 人关注过本帖
标题:Operation not allowed after ResultSet closed
只看楼主 加入收藏
jackflyer
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2016-11-19
结帖率:57.14%
收藏
 问题点数:0 回复次数:2 
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
凌风zx
Rank: 8Rank: 8
来 自:万灵娱乐城
等 级:蝙蝠侠
威 望:7
帖 子:88
专家分:790
注 册:2015-4-11
收藏
得分:0 
倒是没遇到过

再new一个行不

if(tnumber.equals(shnumber)) {
                         stmt1 = conn1.createStatement();
                         stmt1.executeUpdate(sql2);

初出茅庐
2017-05-11 20:19
jackflyer
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2016-11-19
收藏
得分:0 
我已经解决,谢谢大家
2017-05-11 20:57
快速回复:Operation not allowed after ResultSet closed
数据加载中...
 
   



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

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