publicvoidactionPerformed(ActionEvente){if(e.getSource()==bt1){conn=DataBase.getConn();StringuserName=tName.getText().trim();StringuserPassword=newString(pwd.getPassword(...
public void actionPerformed(ActionEvent e) {
if(e.getSource() == bt1){
conn = DataBase.getConn();
String userName = tName.getText().trim();
String userPassword = new String(pwd.getPassword()).trim();
System.out.println(userPassword);
String sql = "select * from zhuce where name = ?";
if(userName.length() == 0 || userPassword.length() == 0){
JOptionPane.showMessageDialog(this, "用户名和密码不能为空!");
tName.requestFocus();
}else{
try{
ps = conn.prepareStatement(sql);
ps.setString(1, userName);
rs = ps.executeQuery();
System.out.println();
if(rs.next()){
if(rs.getString(2).equals(userPassword)){
JOptionPane.showMessageDialog(this, "欢迎进入本系统!");
dispose();
JFrame frame = new MainFrame(userName);
}else{
JOptionPane.showMessageDialog(this, "密码不正确!");
System.out.println();
pwd.setText(null);
pwd.requestFocus();
}
}else{
JOptionPane.showMessageDialog(this, "用户名不存在!");
tName.setText(null);
pwd.setText(null);
tName.requestFocus();
}
}catch(Exception e1){
e1.printStackTrace();
}
}
}
if(e.getSource() == bt2){
tName.setText(null);
pwd.setText(null);
tName.requestFocus();
}
}
展开