1 回答
TA贡献1900条经验 获得超5个赞
也许如果你这样做
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);
和点击事件
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!!!");
}
}
添加回答
举报