当用户验证为“管理员”或“用户”时,我试图调用一个页面,但似乎有问题。
private void validateLogin() {
if (getFieldData() == true) {
username = txtname.getText();
String password = new String(txtpassword.getPassword());
Object type = cbType.getSelectedItem();
//validate login and password here.
//validity will be done by sending login/password to the database
String sql = "select count(*) from usermanagement where UserName='"
+ username + "' and " + "Password='" + password + "'";
ResultSet rs = datacon.queryTable(sql);
try {
rs.next();
if (rs.getInt(1) > 0) {
if (type.equals("Admin")) {
MainMenu mainmenu = new MainMenu();
this.dispose();
mainmenu.setVisible(true);
} else {
UserMenu usermenu = new UserMenu();
this.dispose();
usermenu.setVisible(true);
}
} else {
JOptionPane.showMessageDialog(this,
"Incorrect username or password or user category",
"Error", JOptionPane.ERROR_MESSAGE);
clearField();
txtname.requestFocusInWindow();
cbType.setSelectedIndex(0);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}