java 登录页面问题

NetMatrix NetMatrix 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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();
}
...全文
评论 7
收藏 已收藏
分享
返回顶部
NetMatrix
Java SE 62,621 成员 307,251 内容