Help on changing password code by user using java

Hello Sir. I have difficulty writting out the code to reset user password in the database after login into the application. Here is my code char[] oldPass = jPasswordField1.getPassword(); String strOldPass = new String(oldPass); char[] newPass = jPasswordField2.getPassword(); String strNewPass = new String(newPass); char[] confPass = jPasswordField3.getPassword(); String strConfPass = new String(confPass); try { Inventory objInven = new Inventory();//creating of the objectof the connection in class Inventory. Statement stmt = objinven.con.createStatement(); ResultSet rs = stmt.getResult(); while(rs.next()) { if(rs.getsring("Password").equals(strOldPass)) { rs.moveToInserRow(); rs.updateString("Password", strNewPass); rs.updateString("Password", strConfPass); if(strNewPass.equals(strConfPass)) { JOptionPane.showMessageDialog(this, "Password change successfuly"); } else {JOptionPane.showMessageDialog(this, "Password do not match"); } } else { JOptionPane.showMessageDialog(this, "Wrong old Password"); } } catch(SQLException ex) { ex.printStackTrace(); } } this code is to be performed when a submit button is clicked. i have this error : Exception occurred during event dispatching: jana.lang.NullPointerException. please help me out with this code that will allow users to change their old password to a new one in the database created by correcting my error Thanx

private void btnChangePasswordActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: // TODO add your handling code here: String Newpass=String.valueOf(txtNewPassword.getPassword()); String ConfPass=String.valueOf(txtConfirmPassword.getPassword()); String OldPass=String.valueOf(txtOldPassword.getPassword()); String uName=txtUsername.getText(); if (uName.equals("")) { JOptionPane.showMessageDialog( this, "Please enter a username", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (OldPass.equals("")) { JOptionPane.showMessageDialog( this, "Please enter a old password", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (Newpass.equals("")) { JOptionPane.showMessageDialog( this, "Please enter a new password", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (ConfPass.equals("")) { JOptionPane.showMessageDialog( this, "Please enter a confirmed password", "Error", JOptionPane.ERROR_MESSAGE); return; } else if (Newpass.length() 5) { JOptionPane.showMessageDialog(this, "The New Password Should be of Atleast 5 Characters", "Error", JOptionPane.ERROR_MESSAGE); return; } else if ((Newpass).equals(OldPass)) { JOptionPane.showMessageDialog(this, "Password is same..Re-enter new password","Error", JOptionPane.ERROR_MESSAGE); return; } else if (!(Newpass).equals(ConfPass)) { JOptionPane.showMessageDialog(this, "New Password doesn't match with Confirmed Password", "Error", JOptionPane.ERROR_MESSAGE); return; } try{ con=Connect.ConnectDB(); String sql= "select username,user_password from users"; pst=con.prepareStatement(sql); rs= pst.executeQuery(); while(rs.next()) { String usrname = rs.getString("username").trim(); String passwd = rs.getString("user_password").trim(); if(uName.equals(usrname) && OldPass.equals(passwd)) { con=Connect.ConnectDB(); String sql1= "update users set User_password= '" + Newpass + "' where Username= '" + uName + "' and User_password = '" + OldPass + "'"; Statement stmt = con.createStatement(); stmt.execute(sql1.toString()); stmt.close(); JOptionPane.showMessageDialog(this,"Password Successfully Changed"); txtUsername.setText(""); txtOldPassword.setText(""); txtNewPassword.setText(""); txtConfirmPassword.setText(""); Login frm = new Login(); this.hide(); frm.setVisible(true); } else { JOptionPane.showMessageDialog(this,"invalid user name or password","Error", JOptionPane.ERROR_MESSAGE); txtUsername.setText(""); txtOldPassword.setText(""); txtNewPassword.setText(""); txtConfirmPassword.setText(""); } } }catch(Exception ex){ JOptionPane.showMessageDialog(this,ex); } }

Add new comment