1 回答
TA貢獻(xiàn)1900條經(jīng)驗(yàn) 獲得超5個(gè)贊
也許如果你這樣做
public class UserDAO implements IDao<User> {
DemoDB DemoDBSingleton = null;
public UserDAO() {
DemoDBSingleton = DemoDB.getInstance();
}
@Override
public boolean login(String userName, String password) throws NoSuchElementException {
boolean login = false;
try {
ResultSet resultSet = DemoDBSingleton
.excecuteQuery("SELECT user_name, password FROM users WHERE user_name='" + userName + "' AND password = '" + password + "'");
if (resultSet.next())
login = true;
} catch (SQLException e) {
e.printStackTrace();
}
DemoDBSingleton.close();
return login;
}
}
并更正您的文本字段
JTextField txtUserName = new JTextField(10);
JPasswordField txtPassword = new JPasswordField(10);
和點(diǎn)擊事件
private class ClickListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
UserDAO userDao = new UserDAO();
if (userDao.login(txtUserName.getText(), txtPassword.getText())) {
// here you redirect to your main window
}
else
JOptionPane.showMessageDialog(null, "Incorrect user or password!!!");
}
}
添加回答
舉報(bào)
