java 登录页面问题
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class LoadFrame extends JFrame implements ActionListener{
private JLabel jlb1,jlb2;
private JTextField jtf1;
private JPasswordField jpf;
private JButton jbt1,jbt2;
//public static String name = null;
//public static String password = null;
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
public String s2 = null;
public LoadFrame(){
jlb1 = new JLabel("用户名");
jlb2 = new JLabel("密码");
jtf1 = new JTextField();
jpf = new JPasswordField();
jbt1 = new JButton("登录");
jbt2 = new JButton("退出");
Toolkit tool = this.getToolkit();
Dimension dim = tool.getScreenSize();
int x = (dim.width-380)/2;
int y = (dim.height-300)/2;
this.setTitle("登录窗口");
this.setLayout(null);
this.setBounds(x,y,380,300);
this.setVisible(true);
this.add(jlb1);
jlb1.setBounds(55,55,70,50);
this.add(jtf1);
jtf1.setBounds(120,60,150,30);
this.add(jlb2);
jlb2.setBounds(55,115,70,50);
this.add(jpf);
jpf.setBounds(120,120,150,30);
this.add(jbt1);
jbt1.setBounds(60,180,80,30);
jbt1.addActionListener(this);
this.add(jbt2);
jbt2.setBounds(200,180,80,30);
jbt2.addActionListener(this);
}
public void ConnDB(){
try{
String url = "jdbc:sqlserver://localhost:1433; DatabaseName=Bus";
String userName = "sa";
String userPwd = "1101";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(url,userName,userPwd);
System.out.println("Connected");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jbt2){
dispose();
}
if(e.getSource()==jbt1){
String str1,str2 = null;
ConnDB();
str1 = jtf1.getText();
try{
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from bus_manager where Account='"+str1+"'");
while(rs.next()){
str2 = rs.getString("Password");
System.out.println(str2);
}
String str3 = new String(jpf.getPassword());
System.out.println(str3);
if(str2.equals(str3)){
JOptionPane.showMessageDialog(null,"登录成功");
MainFrame.jmi4.setEnabled(true);
MainFrame.jmi5.setEnabled(true);
dispose();
}else{
JOptionPane.showMessageDialog(null,"登录失败");
}
}catch(SQLException ex){
ex.printStackTrace();
}finally{
try{
rs.close();
conn.close();
stmt.close();
}catch(SQLException en){
en.printStackTrace();
}
}
}
}
}
大家帮我看一下,这段码下面的地方为什么不能执行?
if(str2.equals(str3)){
JOptionPane.showMessageDialog(null,"登录成功");
MainFrame.jmi4.setEnabled(true);
MainFrame.jmi5.setEnabled(true);
dispose();
}