我試圖調用一個頁面,當用戶驗證爲「管理員」或「用戶」,但似乎有問題。桌面應用程序登錄使用計數
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();
}
}
}
是什麼問題? – anshulkatta
1)爲了更快地獲得更好的幫助,請發佈[SSCCE](http://sscce.org/)。 2)請使用代碼格式化代碼,輸入/輸出和結構化文檔,如HTML或XML。爲此,請選擇樣本並單擊郵件發佈/編輯表單上方的「{}」按鈕。 3)*「這裏似乎是一個問題..」*有什麼問題? –
什麼問題? – NINCOMPOOP