The JOptionPane box keeps appearing at least 3 times if I input the incorrect username and password. Firstly, is it even a while loop.
I spent hours looking at the code and trying to modify it but no luck. Couldn't get much help either, but I would greatly appreciate it if someone could point out or fix my error.
The code where I am getting problems is below.
try{
PreparedStatement ps = con.prepareStatement("SELECT Login, Password, Restriction FROM Users");
ResultSet rs = ps.executeQuery();
while(rs.next()){
if (username.equals(rs.getString("Login")) && password.equals(rs.getString("Password")) && ("Admin".equals(rs.getString("Restriction")))){
this.setVisible(false);
MainMenuAdmin admin = new MainMenuAdmin();
admin.setVisible(true);
}
else if (username.equals(rs.getString("Login")) && password.equals(rs.getString("Password")) && ("Engineer".equals(rs.getString("Restriction")))){
this.setVisible(false);
MainMenuEngineer engineer = new MainMenuEngineer();
engineer.setVisible(true);
}
else if (!username.equals(rs.getString("Login")) || !password.equals(rs.getString("Password"))){
JOptionPane.showMessageDialog(null, "Login Failed");
}
}
}
catch(SQLException sqle){
sqle.printStackTrace();
}
Also how do code it such that if a username or password doesn't exist, it says 'Username or Password doesn't exist'?