首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

Connection没关闭呀,为什么出现java.sql.SQLException: ResultSet is closed

2011-12-11 
Connection没有关闭呀,为什么出现java.sql.SQLException: ResultSet is closed?privateTheMainFrameframe

Connection没有关闭呀,为什么出现java.sql.SQLException: ResultSet is closed
private   TheMainFrame   frame   =   new   TheMainFrame();
private   Boolean   flag   =   false;

private   void   jButton1ActionPerformed(java.awt.event.ActionEvent   evt)   {                                                                                  
                try
                {
//DbCon是连接数据库的类,getConnection()是其中得到连接的方法
                        Connection   con   =   new   DbCon().getConnection();
                        Statement   stm   =   con.createStatement();
                        ResultSet   rs=stm.executeQuery( "select   用户名,密码   from   admin   ");
                        while(rs.next())
                        {      
                                String   name   =   rs.getString(1).trim();
                                String   pass   =   rs.getString(2).trim();
                               
                                if   (txtUser.getText().equals(name))
                                {
                                      if(   String.copyValueOf(txtPwd.getPassword()).equals(pass))
                                      {
                                                flag   =   true;
                                                frame.setVisible(true);
                                                dispose();
                                        }
                                        else
                                        {
                                                JOptionPane.showMessageDialog(this, "密码错误 ");


                                                txtPwd.setText( " ");
                                                txtPwd.requestFocus();
                                                return;
                                        }
                                    }
                                    else
                                            continue;
                        }
                        if(flag   ==   false)
                        {      
                                if(!rs.next())
                                {                              
                                                JOptionPane.showMessageDialog(this, "用户名错误 ");
                                                txtUser.setText( " ");
                                                txtUser.requestFocus();
                                                txtPwd.setText( " ");
                                }
                        }
                }catch(SQLException   e)
                {
                        e.printStackTrace();
                }  
        }
是不是哪里不对呀,在netbeans5.0中运行时出现的错误。


[解决办法]
这个类里应该没问题,看看DbCon这个类中是不是关闭了Connection,估计是这个类中返回了一个
Connection,然后直接把他关闭了所造成的Con.close()


[解决办法]
Connection 没有关闭并不表示 ResultSet 也没有关闭。

热点排行