结果集没有当前行

时间:2016-10-08 14:59:08

标签: java jdbc resultset

"结果集没有当前行"此错误仅在第一次出现 然后当我重新设置字段并再次输入详细信息时,这个代码每次都像魅力一样工作,直到我再次关闭并运行程序,我不知道为什么这个东西只出现在第一个项目中我甚至在数据库中创建了我的用户名列主键我在互联网上找到了这个但是没有解决我的问题

private void DoneBtnChangePassMouseClicked(java.awt.event.MouseEvent evt) {                                               


        String db_username , db_pass;

        LogInGUI LG = new LogInGUI();
        LG.Connection();

        String usrname = UsernameFieldCP.getText();
        String CrntPass = CurrentPassFieldCP.getText();
        String newpassfield = NewPassFieldCp.getText();
        String repeatpassfield = RepeatPassFieldCP.getText();

           try
        {
            if(usrname.equals("")){
                JOptionPane.showMessageDialog(this, "Fill The Fields !");
            }
            else{
                if (CrntPass.equals(newpassfield)) {
                    JOptionPane.showMessageDialog(this, "Hah! You Cant Enter The Same Password.");
                }
                else{
                    if(!newpassfield.equals(repeatpassfield)){
                        JOptionPane.showMessageDialog(this, "New Password and Repeat Password Fields Does Not Match !");
                    }
                    else{

            LG.state = LG.conn.createStatement();
            String query = "SELECT Username , Password FROM CreateUser WHERE Username = '"+usrname+"' AND Password = '"+CrntPass+"' ";
            LG.rs = LG.state.executeQuery(query);

            LG.rs.next();

                db_username = LG.rs.getString("Username");
                db_pass = LG.rs.getString("Password");

                if (db_username.equals(usrname) && db_pass.equals(CrntPass))
                {
                    if (newpassfield.equals(repeatpassfield))
                    {
                         LG.state = LG.conn.createStatement();
                         String query1 = "UPDATE CreateUser SET Password = '"+newpassfield+"' WHERE USERNAME = '"+usrname+"' ";
                         LG.state.execute(query1);

                         JOptionPane.showMessageDialog(this, "Password Changed");
                    }
                    else
                    {
                        JOptionPane.showMessageDialog(this, "ReType New Password Correctly");
                    }
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "InCorrect Username Or Password");
                }


                    }
                }
            }
        }
        catch (Exception ex)
        {
            JOptionPane.showMessageDialog(this, ex);
        }

    }

0 个答案:

没有答案