【求助】数据库连接问题,登录界面不能实现???(有源码)
package zxl;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Enter implements ActionListener
{
JTextField user;
JPasswordField passWd;
Container contentPane;
JButton b1,b2;
JPanel pan1,pan2,pan3,pan4;
JFrame bms;
JDialog dialog;
JLabel label;
Connection conn;
Statement stmt;
ResultSet rs;
String str1,str2,name,passwd,sql;
public Enter(JFrame bms)
{
dialog=new JDialog(bms,"登陆",true);
contentPane=dialog.getContentPane();
pan1=new JPanel();
pan2=new JPanel();
pan3=new JPanel();
pan4=new JPanel();
pan1.add(new JLabel("用户",SwingConstants.CENTER));
user=new JTextField("",10);
pan1.add(user);
pan2.add(new JLabel("密码",SwingConstants.CENTER));
passWd=new JPasswordField("",10);
pan2.add(passWd);
b1=new JButton ("确定");
b2=new JButton ("取消");
pan3.add(b1);
pan3.add(b2);
label=new JLabel();
pan4.add(label);
b1.addActionListener(this);
b2.addActionListener(this);
contentPane.setLayout(new GridLayout(4,1));
contentPane.add(pan1);
contentPane.add(pan2);
contentPane.add(pan3);
contentPane.add(pan4);
dialog.setBounds(200,150,250,150);
dialog.show();
}
public void actionPerformed(ActionEvent e)
{
name=user.getText();
passwd=passWd.getText();
label.setText("用户名:"+name+" 密码:"+passwd);
//System.out.println(name+passwd);
if(e.getActionCommand().equals("确定"))
{
sql="select * from USER where NAME='";
sql+=name+"' and PASSWORD='";
sql+=passwd+"'";
System.out.println(sql);
conn=ConnectDB2.getConnection();
rs=ConnectDB2.getResultSet(sql);
if(name.equals("")||passwd.equals(""))
{
JOptionPane.showMessageDialog(dialog, "用户名和密码不能为空!");
}
try
{
while(rs.next())
{
str1=rs.getString(1);
str2=rs.getString(2);
System.out.println(str1);
if(name.equals(str1))
{
System.out.println(str2);
JOptionPane.showMessageDialog(dialog, "登陆成功");
}
} }
catch(Exception ec)
{
}
ConnectDB2.disConnection(conn);
}
if(e.getActionCommand().equals("取消"))
{
System.exit(0);
}
}
}
我编译之后,上面标注的那段不能实现!
不知道为什么弹不出登录窗口。
请高手看看!