管理系统

来源:互联网 发布:mysql 自增函数 编辑:程序博客网 时间:2024/05/17 03:40

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.sql.*;

 

                                                     //主窗口

class QingDan extends JFrame implements ActionListener{

 

   JLabel JL1,JL2;

   JButton JB1,JB2;

 

   QingDan(){

     super("商品管理系统");

     this.getContentPane().setLayout(null);     

 

     JL1 = new JLabel("欢迎光临商品管理系统");      //设置标签信息

     this.getContentPane().add(JL1);

     JL1.setBounds(100,70,220,50);

     JL1.setForeground(Color.blue);       

     JL1.setFont(new Font("黑体",Font.BOLD,20));    //设置标签字体,大小

 

     JB1 = new JButton("查询商品信息") ;            //设置按钮信息

     JB2 = new JButton("管理者进入");

     this.getContentPane().add(JB1);

     this.getContentPane().add(JB2);    

     JB1.setBounds(70,150,120,40);

     JB2.setBounds(220,150,120,40);

     JB1.addActionListener(this);                   //注册事件监听器

     JB2.addActionListener(this);                

 

     this.setSize(400,300);

     this.setLocationRelativeTo(null);              //使窗口显示在屏幕中央    

     this.setVisible(true);

     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       //设置关闭动作

 

   }

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                        //JB1的事件处理器,进入查询窗口

       Checking a=new Checking();

     }    

     if(e.getSource()==JB2){                        //JB2的事件处理器,进入登录窗口

       Loading b=new Loading();

     }           

   }

}

 

 

                                                    //商品查询窗口

class Checking extends JFrame implements ActionListener{

 

   JLabel JL1,JL2;

   JTextField JT1;

   JButton JB1,JB2;

 

   Checking(){

     super("商品查询界面");

     this.getContentPane().setLayout(null);                    

 

     JT1 = new  JTextField(10);                      //设置文本框信息 

     this.getContentPane().add(JT1);       

     JT1.setBounds(140,80,120,40);                   

 

     JL1 = new JLabel("请输入您所要查询的商品号!"); //设置标签框信息

     JL2 = new JLabel("商品号:");     

     this.getContentPane().add(JL1);       

     this.getContentPane().add(JL2);     

     JL1.setBounds(20,20,250,40);      

     JL2.setBounds(40,80,70,40);     

     JL1.setForeground(Color.blue); 

     JL2.setForeground(Color.red);      

     JL1.setFont(new Font("宋体",Font.BOLD,18));   //设置标签字体,大小

     JL2.setFont(new Font("幼圆",Font.BOLD,18));      

 

     JB1 = new  JButton("确定");                    //设置按钮信息

     JB2 = new  JButton("退出");

     this.getContentPane().add(JB1);

     this.getContentPane().add(JB2);       

     JB1.setBounds(40,140,90,40);

     JB2.setBounds(170,140,90,40);        

     JB1.addActionListener(this);                 //注册事件监听器

     JB2.addActionListener(this);                 

 

     this.setSize(300,300);

     this.setLocationRelativeTo(null);       

     this.setVisible(true);       

  } 

  

  public void actionPerformed(ActionEvent e){

    if(e.getSource()==JB1){                                   //JB1的事件处理器,进入商品信息窗口

      if(JT1.getText().length() < 1){

        JOptionPane.showMessageDialog(this,"商品号不能为零!");

      }

      else{    

        try{ 

          String URL ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=M://QingDan.mdb"; //数据库的路径

     Connection con = DriverManager.getConnection(URL);  //连接数据库

     Statement  stmt = con.createStatement();            //创建Statement对象

     ResultSet  rs = stmt.executeQuery("Select * From Q1 Where number="+Integer.parseInt(JT1.getText()));//定义数据库查询的结果和执行查询语句 

     String number,name,money,count;  

     JT1.setText("");                                    //清空文本框 

                     

     if(rs.next()==false){                               //判断数据库中是否有要查询的商品的记录,如没有则输出提示框

       JOptionPane.showMessageDialog(this,"数据库中没有相关的商品信息,请重新输入!"); 

     }

     else{  

       number=rs.getString(1);

       name=rs.getString(2);

       money=rs.getString(3);

       count=rs.getString(4);

            Information aa=new Information();    //连接到商品信息窗口      

            aa.JT1.setText(number);              //把查询结果输出到窗口中

            aa.JT2.setText(name); 

            aa.JT3.setText(money); 

            aa.JT4.setText(count);

       this.hide();              

    }

         rs.close();                            //关闭结果集

         stmt.close();                          //关闭Statement接口

         con.close();                           //关闭Connection接口 

   }

        catch(SQLException a){                  //捕捉异常

         a.printStackTrace();

   }

      }

    }      

    if(e.getSource()==JB2){                     //JB2的事件处理器,隐藏查询窗口

      this.hide();

    }           

  } 

}

 

 

                                               //登陆窗口

class Loading extends JFrame implements ActionListener{

 

   JLabel JL1,JL2,JL3;

   JTextField JT1;

   JPasswordField JP;

   JButton JB1 ,JB2;   

 

   Loading(){

     super("登录界面");

     this.getContentPane().setLayout(null);             

 

     JL1 = new JLabel("请输入管理帐号和密码!");     //设置标签信息

     JL2 = new JLabel("管理帐号");

     JL3 = new JLabel("密码"); 

     this.getContentPane().add(JL1);      

     this.getContentPane().add(JL2);

     this.getContentPane().add(JL3);        

     JL1.setBounds(30,10,260,40);

     JL2.setBounds(50,70,70,40);

     JL3.setBounds(50,120,60,40);  

     JL1.setForeground(Color.blue); 

     JL2.setForeground(Color.red);

     JL3.setForeground(Color.red);  

     JL1.setFont(new Font("宋体",Font.BOLD,20));   //设置标签字体,大小

     JL2.setFont(new Font("幼圆",Font.BOLD,16));

     JL3.setFont(new Font("幼圆",Font.BOLD,16));      

 

     JT1 = new  JTextField(10);                    //设置文本框信息

     JP = new  JPasswordField(10);

     this.getContentPane().add(JT1);

     this.getContentPane().add(JP);      

     JT1.setBounds(150,70,100,40);    

     JP.setBounds(150,120,100,40);  

     JT1.setFont(new Font("黑体",Font.BOLD,18));  //设置文本框字体,大小

     JP.setFont(new Font("",Font.BOLD,18));             

 

     JB1 = new  JButton("登陆");                   //设置按钮信息

     JB2 = new  JButton("取消");

     this.getContentPane().add(JB1);     

     this.getContentPane().add(JB2);          

     JB1.setBounds(60,180,60,40);  

     JB2.setBounds(160,180,60,40);    

     JB1.addActionListener(this);                  //注册事件监听器

     JB2.addActionListener(this);                

 

     this.setSize(300,300);

     this.setLocationRelativeTo(null);             //使窗口显示在屏幕中央 

     this.setVisible(true);

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                      //JB1的事件处理器

       if(JT1.getText().equals("root")&&JP.getText().equals("123456")){    //判断管理帐号和密码是否正确,正确的话就输出提示框

    JOptionPane.showMessageDialog(this,"登入成功!");                      

         Operation  aa =new Operation();          //进入操作窗口

this.hide();                             //隐藏登录窗口

  }

  else{

  if(JT1.getText().length() < 1||JP.getText().length() < 1){        //判断登录时的情况

  JOptionPane.showMessageDialog(this,"管理帐号或密码没填写!");      

         }

         else  JOptionPane.showMessageDialog(this,"管理帐号或密码不正确!"); 

       } 

     }  

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

       this.hide();                              //隐藏登录窗口

     }          

   }          

}

 

 

                                                //选择操作窗口

class Operation extends JFrame implements ActionListener{

 

   JButton JB1,JB2,JB3,JB4;   

   String number,name,money,count;  

 

   Operation(){

super("选择操作");

     this.getContentPane().setLayout(null); 

 

     JB1 = new  JButton("增加商品信息");        //设置按钮信息

     JB2 = new  JButton("更改商品信息");

     JB3 = new  JButton("删除商品信息");

     JB4 = new  JButton("    退出    ");

     this.getContentPane().add(JB1);     

     this.getContentPane().add(JB2);  

     this.getContentPane().add(JB3);     

     this.getContentPane().add(JB4);          

     JB1.setBounds(80,10,120,40);  

     JB2.setBounds(80,80,120,40);   

     JB3.setBounds(80,150,120,40);  

     JB4.setBounds(80,220,120,40);    

     JB1.addActionListener(this);              //注册事件监听器

     JB2.addActionListener(this);                 

     JB3.addActionListener(this);                 

     JB4.addActionListener(this);                 

 

     this.setSize(300,300);  

     this.setLocationRelativeTo(null);        //使窗口显示在屏幕中央 

     this.setVisible(true);

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){             //JB1的事件处理器,进入增加商品窗口

       Adding aa = new Adding();       

     }  

     if(e.getSource()==JB2){                //JB2的事件处理器,进入更改商品窗口

       JOptionPane.showMessageDialog(this,"在更改商品信息之前,请先确认该商品信息!");

       Change bb = new Change();

       Checking dd = new Checking();        //进入商品查询窗口,先查询商品信息

     }         

     if(e.getSource()==JB3){            //JB3的事件处理器,进入删除商品窗口

       JOptionPane.showMessageDialog(this,"在删除商品信息之前,请先确认该商品信息!");

       Delete cc = new Delete();

       Checking dd = new Checking();   //进入商品查询窗口,先查询商品信息

     }    

     if(e.getSource()==JB4){               //JB4的事件处理器,隐藏窗口

       this.hide();

     }      

   }  

}     

 

 

                                                         //商品信息窗口

class Information extends JFrame implements ActionListener{    

 

   JLabel JL1,JL2,JL3,JL4;

   JTextField JT1,JT2,JT3,JT4;

   JButton JB1,JB2,JB3,JB4;

   Connection conn = null;

   ResultSet rs = null;

   Statement stmt = null;  

 

   Information(){

super("商品查询信息");

     this.getContentPane().setLayout(null);    

 

     JL1 = new JLabel("商品号");                        //设置标签信息

     JL2 = new JLabel("商品名称");

     JL3 = new JLabel("商品价格"); 

     JL4 = new JLabel("商品存货");

     this.getContentPane().add(JL1);

     this.getContentPane().add(JL2);

     this.getContentPane().add(JL3);

     this.getContentPane().add(JL4);          

     JL1.setBounds(45,20,120,40);

     JL2.setBounds(45,70,120,40);

     JL3.setBounds(45,120,120,40);         

     JL4.setBounds(45,170,120,40);  

     JL1.setForeground(Color.red);

     JL2.setForeground(Color.red);   

     JL3.setForeground(Color.red);

     JL4.setForeground(Color.red); 

     JL1.setFont(new Font("黑体",Font.BOLD,15));       //设置标签字体,大小

     JL2.setFont(new Font("黑体",Font.BOLD,15));

     JL3.setFont(new Font("黑体",Font.BOLD,15));

     JL4.setFont(new Font("黑体",Font.BOLD,15));         

 

     JT1 = new  JTextField(10);                        //设置文本框信息

     JT2 = new  JTextField(10);

     JT3 = new  JTextField(10);

     JT4 = new  JTextField(10);

     this.getContentPane().add(JT1);

     this.getContentPane().add(JT2);

     this.getContentPane().add(JT3);

     this.getContentPane().add(JT4);      

     JT1.setBounds(140,20,130,40);    

     JT2.setBounds(140,70,130,40);   

     JT3.setBounds(140,120,130,40);

     JT4.setBounds(140,170,130,40);        

 

     JB1 = new  JButton("重新查询");                   //设置按钮信息

     JB2 = new  JButton("退出");

     this.getContentPane().add(JB1);     

     this.getContentPane().add(JB2);         

     JB1.setBounds(30,220,100,40);  

     JB2.setBounds(160,220,100,40);      

     JB1.addActionListener(this);              //注册事件监听器

     JB2.addActionListener(this);          

 

     this.setSize(300,300);

     this.setLocationRelativeTo(null);         //使窗口显示在屏幕中央 

     this.setVisible(true);

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                   //JB1的事件处理器,隐藏商品信息窗口,进入商品查询窗口

       this.hide();

       Checking aa = new Checking();

       JT1.setText("");                        //清空文本框

  JT2.setText("");

  JT3.setText("");

  JT4.setText("");

     }         

     if(e.getSource()==JB2){                   //JB2的事件处理器,隐藏窗口

       this.hide();

     } 

   }

}

 

 

                                              //增加商品窗口

class Adding extends JFrame implements ActionListener{    

 

   JLabel JL1,JL2,JL3,JL4;

   JTextField JT1,JT2,JT3,JT4;

   JButton JB1,JB2,JB3,JB4;

   Connection  con = null;

   Statement  stmt = null;

   ResultSet  rs = null;

 

   Adding(){

super("增加商品");

    this.getContentPane().setLayout(null);   

 

    JL1 = new JLabel("商品号");               //设置标签信息

    JL2 = new JLabel("商品名称");

    JL3 = new JLabel("商品价格"); 

    JL4 = new JLabel("商品存货");

    this.getContentPane().add(JL1);

    this.getContentPane().add(JL2);

    this.getContentPane().add(JL3);

    this.getContentPane().add(JL4);        

    JL1.setBounds(45,20,120,40);

    JL2.setBounds(45,70,120,40);

    JL3.setBounds(45,120,120,40);         

    JL4.setBounds(45,170,120,40);   

    JL1.setForeground(Color.red);

    JL2.setForeground(Color.red);   

    JL3.setForeground(Color.red);

    JL4.setForeground(Color.red); 

    JL1.setFont(new Font("黑体",Font.BOLD,15));       //设置标签字体,大小

    JL2.setFont(new Font("黑体",Font.BOLD,15));

    JL3.setFont(new Font("黑体",Font.BOLD,15));

    JL4.setFont(new Font("黑体",Font.BOLD,15));         

 

    JT1 = new  JTextField(10);                        //设置文本框信息

    JT2 = new  JTextField(10);

    JT3 = new  JTextField(10);

    JT4 = new  JTextField(10);

    this.getContentPane().add(JT1);

    this.getContentPane().add(JT2);

    this.getContentPane().add(JT3);

    this.getContentPane().add(JT4);       

    JT1.setBounds(140,20,130,40);    

    JT2.setBounds(140,70,130,40);   

    JT3.setBounds(140,120,130,40);

    JT4.setBounds(140,170,130,40);        

 

    JB1 = new  JButton("确定");                     //设置按钮信息

    JB2 = new  JButton("退出");

    JB1.setBounds(40,220,100,40);  

    JB2.setBounds(170,220,100,40);   

    this.getContentPane().add(JB1);     

    this.getContentPane().add(JB2);    

    JB1.addActionListener(this);                  //注册事件监听器

    JB2.addActionListener(this);        

 

    this.setSize(300,300);

    this.setLocationRelativeTo(null);             //使窗口显示在屏幕中央 

    this.setVisible(true);

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                  //JB1的事件处理器

       if(JT1.getText().length() < 1||JT2.getText().length() < 1||JT3.getText().length() < 1||JT4.getText().length() < 1){  //判断输入信息是否完整

         JOptionPane.showMessageDialog(this,"商品信息填写不完整!");

       }

       else{ 

         String number,name,money,count;   

         number = JT1.getText();                  //帮数据库中相应的信息赋值给对应的变量

         name = JT2.getText();

         money = JT3.getText(); 

         count = JT4.getText();

 

         try { 

           String URL ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=QingDan.mdb"; //数据库的路径

      con = DriverManager.getConnection(URL);            //连接数据库

      stmt = con.createStatement();                      //创建Statement对象  

      rs = stmt.executeQuery("Select * From Q1 Where number="+Integer.parseInt(JT1.getText()));//定义数据库查询的结果和执行查询语句 

               

      if(rs.next()==true){                               //判断数据库中是否有要查询的商品的记录,如没有则输出提示框

        JOptionPane.showMessageDialog(this,"商品号重复,数据库中已存在该商品号信息,请重新输入!"); 

      }

      else{                                              //像数据库中添加商品信息

        int x= stmt.executeUpdate("Insert INTO Q1 Values("+number+",'"+name+"','"+money+"','"+count+"')"); 

        JOptionPane.showMessageDialog(this,"操作成功!");

      } 

      JT1.setText("");                                   //清空文本框

      JT2.setText("");

      JT3.setText("");

      JT4.setText("");

 

         }catch(SQLException a){                              //捕捉异常

            a.printStackTrace();

}

try{

  rs.close();                                        //关闭结果集

  stmt.close();                                      //关闭Statement接口

           con.close();                                       //关闭Connection接口 

}catch(SQLException c){                              //捕捉异常

}                  

       }           

     } 

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

       this.hide();                                           //JB2的事件处理器,隐藏窗口

     }

   }

}

 

 

                                                             //更改商品信息窗口

class Change extends JFrame implements ActionListener{    

 

   JLabel JL1,JL2,JL3,JL4;

   JTextField JT1,JT2,JT3,JT4;

   JButton JB1,JB2,JB3,JB4;

   Connection  con = null;

   Statement  stmt = null;

   ResultSet  rs = null;

 

   Change(){

super("更改商品信息");

     this.getContentPane().setLayout(null);

 

     JL1 = new JLabel("商品号");                              //设置标签信息

     JL2 = new JLabel("商品名称");

     JL3 = new JLabel("商品价格"); 

     JL4 = new JLabel("商品存货");

     this.getContentPane().add(JL1);

     this.getContentPane().add(JL2);

     this.getContentPane().add(JL3);

     this.getContentPane().add(JL4);   

     JL1.setBounds(40,20,80,40);

     JL2.setBounds(40,70,80,40);

     JL3.setBounds(40,120,80,40);         

     JL4.setBounds(40,170,80,40);       

     JL1.setForeground(Color.red);

     JL2.setForeground(Color.red);   

     JL3.setForeground(Color.red);

     JL4.setForeground(Color.red); 

     JL1.setFont(new Font("黑体",Font.BOLD,15));            //设置标签字体,大小

     JL2.setFont(new Font("黑体",Font.BOLD,15));

     JL3.setFont(new Font("黑体",Font.BOLD,15));

     JL4.setFont(new Font("黑体",Font.BOLD,15));                

 

     JT1 = new  JTextField(10);                             //设置文本框信息

     JT2 = new  JTextField(10);

     JT3 = new  JTextField(10);

     JT4 = new  JTextField(10);

     this.getContentPane().add(JT1);

     this.getContentPane().add(JT2);

     this.getContentPane().add(JT3);

     this.getContentPane().add(JT4);      

     JT1.setBounds(120,20,130,40);    

     JT2.setBounds(120,70,130,40);   

     JT3.setBounds(120,120,130,40);

     JT4.setBounds(120,170,130,40);           

 

     JB1 = new  JButton("更改保存");                      //设置按钮信息

     JB2 = new  JButton("退出");

     this.getContentPane().add(JB1);     

     this.getContentPane().add(JB2);        

     JB1.setBounds(35,220,100,40);  

     JB2.setBounds(165,220,100,40);     

     JB1.addActionListener(this);                       //注册事件监听器

     JB2.addActionListener(this);        

 

     this.setSize(300,300);

     this.setLocationRelativeTo(null);                 //使窗口显示在屏幕中央 

     this.setVisible(true);

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                       //JB1的事件处理器,进行更改商品信息操作

       if(JT1.getText().length() < 1||JT2.getText().length() < 1||JT3.getText().length() < 1||JT4.getText().length() < 1){

         JOptionPane.showMessageDialog(this,"商品信息填写不完整!");

       }

       else{ 

         String number,name,money,count;    

         number = JT1.getText();                       //帮数据库中相应的信息赋值给对应的变量

         name = JT2.getText();

         money = JT3.getText(); 

         count = JT4.getText();

 

         try { 

           String URL ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=QingDan.mdb"; //数据库的路径

      con = DriverManager.getConnection(URL);     //连接数据库

      stmt = con.createStatement();               //创建Statement对象  

      rs = stmt.executeQuery("Select * From Q1 Where number="+Integer.parseInt(JT1.getText()));//定义数据库查询的结果和执行查询语句 

               

      if(rs.next()==false){                       //判断数据库中是否有要查询的商品的记录,如没有则输出提示框

        JOptionPane.showMessageDialog(this,"数据库中没有相关的商品信息,请重新输入!"); 

      }

      else{                                       //删除数据库中原有的商品信息 

        int x= stmt.executeUpdate("Delete from Q1 where number ="+Integer.parseInt(JT1.getText()));  

        int y= stmt.executeUpdate("Insert INTO Q1 Values("+number+",'"+name+"','"+money+"','"+count+"')");  //像数据库中添加商品信息

        JOptionPane.showMessageDialog(this,"操作成功!");

      } 

      JT1.setText("");                            //清空文本框

      JT2.setText("");

      JT3.setText("");

      JT4.setText("");

 

         }catch(SQLException a){                       //捕捉异常            

            a.printStackTrace();

  }

  try{

    rs.close();                                //关闭结果集

    stmt.close();                              //关闭Statement接口

           con.close();                               //关闭Connection接口 

  }catch(SQLException c){                      //捕捉异常

  }                  

       }           

     } 

     if(e.getSource()==JB2){                          //JB2的事件处理器,隐藏窗口

       this.hide();

     }

   }

}

 

 

                                                    //删除商品窗口

class Delete extends JFrame implements ActionListener{    

 

   JLabel JL1,JL2;

   JTextField JT1;

   JButton JB1,JB2,JB3,JB4;

   Connection  con = null;

   Statement  stmt = null;

   ResultSet  rs = null;

 

   Delete(){

     super("商品删除界面");

     this.getContentPane().setLayout(null);     

 

     JT1 = new  JTextField(10);                     //设置文本框信息

     this.getContentPane().add(JT1);    

     JT1.setBounds(160,80,120,40);          

 

     JL1 = new JLabel("请输入您所要删除的商品号!");    //设置标签信息

     JL2 = new JLabel("要删除的商品号:");       

     this.getContentPane().add(JL1);       

     this.getContentPane().add(JL2);       

     JL1.setBounds(20,20,250,40);      

     JL2.setBounds(20,80,130,40);          

     JL1.setForeground(Color.blue); 

     JL2.setForeground(Color.red);     

     JL1.setFont(new Font("黑体",Font.BOLD,18));      

     JL2.setFont(new Font("隶书",Font.BOLD,16));       

 

     JB1 = new  JButton("确定");                 //设置按钮信息

     JB2 = new  JButton("退出");

     this.getContentPane().add(JB1);

     this.getContentPane().add(JB2);      

     JB1.setBounds(50,160,90,40);

     JB2.setBounds(170,160,90,40);        

     JB1.addActionListener(this);                //注册事件监听器

     JB2.addActionListener(this);      

 

     this.setSize(300,300);

     this.setLocationRelativeTo(null);           //使窗口显示在屏幕中央 

     this.setVisible(true);      

   }  

 

   public void actionPerformed(ActionEvent e){

     if(e.getSource()==JB1){                     //JB1的事件处理器,进行删除操作

       if(JT1.getText().length() < 1){

         JOptionPane.showMessageDialog(this,"商品号不能为零!");

       } 

       else{  

         String number = JT1.getText();            

           try { 

             String URL ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=QingDan.mdb"; //数据库的路径

        con = DriverManager.getConnection(URL);             //连接数据库

        stmt = con.createStatement();                       //创建Statement对象  

        rs = stmt.executeQuery("Select * From Q1 Where number="+Integer.parseInt(JT1.getText()));//定义数据库查询的结果和执行查询语句 

               

        if(rs.next()==false){                               //判断数据库中是否有要查询的商品的记录,如没有则输出提示框

          JOptionPane.showMessageDialog(this,"数据库中没有相关的数据,请重新输入!"); 

        }

        else{                                               //删除商品信息

          int x= stmt.executeUpdate("Delete from Q1 where number ="+Integer.parseInt(JT1.getText())); 

          JOptionPane.showMessageDialog(this,"操作成功!"); //删除成功的话就输出提示框

        } 

        JT1.setText("");                                    //清空文本框

           }catch(SQLException a){                               //捕捉异常

              a.printStackTrace();

  }

  try{

    rs.close();                                         //关闭结果集

        stmt.close();                                       //关闭Statement接口

             con.close();                                        //关闭Connection接口 

  }catch(SQLException c){                               //捕捉异常

  }

       }                    

     }           

     if(e.getSource()==JB2){                                     //JB2的事件处理器,隐藏窗口

       this.hide();

     }

   }

}

 

 

 

class QingDanTest{

   public static void main(String arg[])throws Exception {

   QingDan ee = new QingDan(); 

   } 

}

原创粉丝点击