Java报错exception in thread awt-eventqueue-0这个怎么解决呀

public void actionPerformed(ActionEvent e) {

  flag=0;

     try{

   String num,name,gender,address,phone,major;

   con=DriverManager.getConnection(“jdbc:mysql://localhost:3306/university?characterEncoding=utf8″,”root”,”123456″);

   num=t1.getText().trim();

   ResultSet rs=sql.executeQuery(“SELECT * FROM student WHERE id='”+num+”‘”);

   if(rs.next()){

       name=rs.getString(“name”);

       gender=rs.getString(“gender”);

       address=rs.getString(“address”);

       phone=rs.getString(“phone”);

       major=rs.getString(“major”);

         t2.setText(name);

         t3.setText(gender);

         t4.setText(address);

         t5.setText(phone);

         t6.setText(major);

         if(e.getSource()==b2){

         String temp=”DELETE FROM student WHERE id='”+num+”‘”;

       sql.executeUpdate(temp);

  JOptionPane.showMessageDialog(this,”删除成功!”,”提示对话框”,JOptionPane.INFORMATION_MESSAGE);

         }

         flag=1;

   }else{

      JOptionPane.showMessageDialog(this,”没有该学生!”,”提示对话框”,JOptionPane.INFORMATION_MESSAGE);

   }

   con.close();

   if(flag==0){t1.setText(“没有该学生”);}

   }

     catch(SQLException ee){}

 }

}

错误

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException: Cannot invoke “java.sql.Statement.executeQuery(String)” because “this.sql” is null

 at GUI.StudentDelete.actionPerformed(StudentDelete.java:90)

 at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1972)

 at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2313)

 at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)

 at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)

 at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)

 at java.desktop/java.awt.Component.processMouseEvent(Component.java:6626)

 at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3389)

 at java.desktop/java.awt.Component.processEvent(Component.java:6391)

 at java.desktop/java.awt.Container.processEvent(Container.java:2266)

 at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)

 at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)

 at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)

 at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4948)

 at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4575)

 at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4516)

 at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2310)

 at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)

 at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)

 at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)

 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)

 at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)

 at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)

 at java.base/java.security.ProtectionDomain$JavaSecurityA

d5893f4731d2490bb42cbf8c8350ed0a.png

 

版权声明:本文为博主作者:2301_80063093原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/2301_80063093/article/details/135023741

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2024年1月8日
下一篇 2024年1月8日

相关推荐

此站出售,如需请站内私信或者邮箱!