这是部分代码。。。。stuLogin.addActionListener(this);teaLogin.addActionListener(this);setBounds(500,300,300,250);setVisible(true);validate();setDefaultCloseOperation(JFra...
这是部分代码。。。。
stuLogin.addActionListener(this);
teaLogin.addActionListener(this);
setBounds(500,300,300,250);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{Object obj=e.getSource();
if(obj==teaLogin)
{
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost:3306/bookmanagement","root","000");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select
mgNO,password from manager where mgNO='"+text1.getText()+"' and
password='"+text2.getText()+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"登陆成
功!");
}
else
JOptionPane.showMessageDialog(null,"用户名或密
码错误!");
}
catch(Exception ex){}
}
else if(obj==stuLogin)
{
try{
Class.forName("com.mysql.jdbc.Driver");//mysql数
据库
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost:3306/bookmanagement","root","000");
Statement cmd=con.createStatement();
ResultSet rs=cmd.executeQuery("select
StuNO,Password from student where StuNO='"+text1.getText()+"' and
Password='"+text2.getText()+"'");
if(rs.next())
{
JOptionPane.showMessageDialog(null,"登陆成
功!");
}
else
JOptionPane.showMessageDialog(null,"用户名或密
码错误!");
}
catch(Exception ex){}
}
}}
public class Login
{public static void main(String args[])
{Denglu win=new Denglu("登录");
}
}
点击按钮就出现这个:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
展开