I've inserted awt choice class for choices(Admin, User) and using if-else I wanna engage table admins(with columns 'username' and 'password') when c=="Admin"(or c.equals(Admin)) and table users(with columns 'username' and 'pass') when c is anything else.
while everything's good with admin login, user login will always give an error. error: Invalid Username or Password which comes from else block that's inside try block of user login part.
any suggestions on this?
if(c.equals("Admin")){
users.admin=1;
try{
String sql="select * from admins where username=? and password=?";
pst=conn.prepareStatement(sql);
pst.setString(1, TF_USER.getText());
pst.setString(2, PW.getText());
rs=pst.executeQuery();
if(rs.next()){
WelcomeUser j = new WelcomeUser();
j.setVisible(true);
this.dispose();
}
else{
JOptionPane.showMessageDialog(null,"Invalid Username or Password","Action Deinied",JOptionPane.ERROR_MESSAGE);
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}
else{
users.admin=0;
try{
String Sql="select * from users where username=? and pass=?";
pst=conn.prepareStatement(Sql);
pst.setString(1, TF_USER.getText());
pst.setString(2, PW.getText());
rs=pst.executeQuery();
if(rs.next()){
WelcomeUser j = new WelcomeUser();
j.setVisible(true);
this.dispose();
}
else{
JOptionPane.showMessageDialog(null,"Invalid Username or Password","Action Deinied",JOptionPane.ERROR_MESSAGE);
}
}
catch(Exception e){
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}
}