我在如何连接我的两个班级时遇到问题。我想要发生的是,当用户登录时,GradingSystem
该类将运行并根据我的 MS ACCESS 数据库自动显示用户的信息。不知何故,我不知道如何调用登录类或将登录类连接到其他类。
登录课程
private class ButtonHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
DatabaseDriver driver = new DatabaseDriver();
Object source = e.getSource();
if (source == btnLogin) {
try {
String username = txtUserName.getText();
String password = String.valueOf(txtPassword.getPassword());
String query =
"Select username,password from [useraccount] where [username]='"
+ username + "' and [password]='" + password+"'";
driver.selectQuery(query);
ResultSet rsLogin = driver.rs;
if (rsLogin.next()) {
String logo = "img/seal_TIP.png";
java.net.URL addURL = getClass().getClassLoader().getResource(logo);
ImageIcon image1 = new ImageIcon(addURL);
JOptionPane.showMessageDialog(null, "Welcome to your TIP account.",
"Login Success", JOptionPane.INFORMATION_MESSAGE, image1);
dispose();
new GradingSystem().run();
} else {
JOptionPane.showMessageDialog(null, "Incorrect Username or Password.",
"User Not Found!", JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException ex) {
}
分级系统类
DatabaseDriver driver = new DatabaseDriver();
String query = "Select lastName from [useraccount] where [username]='"
+login.username+"' and [password]='"+login.password+"'";
driver.selectQuery(query);
ResultSet rsGradingSystem = driver.rs;
try {
if (rsGradingSystem.next()) {
JLabel studName= new JLabel("Name: ");
studName.setBounds(15,60,150,20);
add(studName);
}
} catch (SQLException ex) {
}