⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ydq.java

📁 学生信息管理系统
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    p8.add(button2,"East");
    p9.add(p1,"North");
    p9.add(p2,"Center");
    p9.add(p3,"South");
    p10.add(p4,"North");
    p10.add(p5,"East");
    p10.add(p6,"South");
    p11.add(p7,"North");
    p11.add(p8,"Center");
    p12.add(p9,"North");
    p12.add(p10,"Center");
    p12.add(p11,"South");
    add(p12);
    addWindowListener (new WindowAdapter()
       {public void windowClosing(WindowEvent e)
          {dispose();}
       }
    );
   }
   public void actionPerformed(ActionEvent e)
   {if(e.getSource()==button1)
    { try
      {chaxun();
      }
      catch(Exception e8 ) {}
    }
    else if(e.getSource()==button2)
    { try
      {genggai();
      }
      catch(Exception e9 ) {}
    }
    else if(e.getSource()==button3)
    {try
      {tianjia();
      }
      catch(Exception e9 ) {}
    }
   }
   public void chaxun() throws SQLException
   {
      try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      rs=sql.executeQuery("select * from gerenxinxi where 用户名="+xuehao);
      while(rs.next())
      {   String qq1=rs.getString("姓名");
          String qq2=rs.getString("性别");
          String qq3=rs.getString("出生日期");
          String qq4=rs.getString("家庭住址");
          String qq5=rs.getString("院系");
          String qq6=rs.getString("班级");
          String qq7=rs.getString("爱好");
          text1.setText(qq1);
          text2.setText(qq2);
          text3.setText(qq3.substring(0,10));
          text4.setText(qq4);
          text5.setText(qq5);
          text6.setText(qq6);
          text7.setText(qq7);
          con.close();
          return;
      }
      JOptionPane.showMessageDialog(this,"该用户不存在","提示",JOptionPane.WARNING_MESSAGE);    
   }
   public void genggai()  throws SQLException
   {  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      String q1="'"+text1.getText().trim()+"'";
      String q2="'"+text2.getText().trim()+"'";
      String q3="'"+text3.getText().trim()+"'";
      String q4="'"+text4.getText().trim()+"'";
      String q5="'"+text5.getText().trim()+"'";
      String q6="'"+text6.getText().trim()+"'";
      String q7="'"+text7.getText().trim()+"'";
      sql.executeUpdate("update gerenxinxi set 姓名="+q1+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 性别="+q2+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 出生日期="+q3+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 家庭住址="+q4+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 院系="+q5+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 班级="+q6+" where 用户名="+xuehao);
      sql.executeUpdate("update gerenxinxi set 爱好="+q7+" where 用户名="+xuehao);
      JOptionPane.showMessageDialog(this,"修改信息成功","提示",JOptionPane.WARNING_MESSAGE);
      con.close();
    }
     public void tianjia()  throws SQLException
   {  try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      String q1="'"+text1.getText().trim()+"'";
      String q2="'"+text2.getText().trim()+"'";
      String q3="'"+text3.getText().trim()+"'";
      String q4="'"+text4.getText().trim()+"'";
      String q5="'"+text5.getText().trim()+"'";
      String q6="'"+text6.getText().trim()+"'";
      String q7="'"+text7.getText().trim()+"'";
      sql.executeUpdate("insert into  gerenxinxi values("+xuehao+","+q1+","+q2+","+q3+","+q4+","+q5+","+q6+","+q7+")");
      JOptionPane.showMessageDialog(this,"添加信息成功","提示",JOptionPane.WARNING_MESSAGE);
      con.close();
    }
   }
   class xuanke extends Frame implements ActionListener,ItemListener
   { Label label1,label2,label3,label4,label5;
     TextField text1,text2,text3,text4;
     Choice choice;
     Button button1,button2;
     Connection con=null;
     Statement sql=null;
     ResultSet rs=null;
     xuanke()
    {super("选课信息管理页面");
     setBackground(color);
     setSize(400,400);
     setBounds(200,200,600,300);
     setVisible(false);
     label1=new Label("课程号");
     label2=new Label("课程名");
     label3=new Label("教师");
     label4=new Label("学时");
     label5=new Label("上课地点");
     choice=new Choice();
     text1=new TextField(10);
     text2=new TextField(10);
     text3=new TextField(10);
     text4=new TextField(10);
     button1=new Button("选修");
     button2=new Button("退选");
     button1.addActionListener(this);
     button2.addActionListener(this);
     choice.addItemListener(this);
     Panel p1=new Panel();
     Panel p2=new Panel();
     Panel p3=new Panel();
     Panel p4=new Panel();
     Panel p5=new Panel();
     Panel p6=new Panel();
     Panel p7=new Panel();
     Panel p8=new Panel();
     Panel p9=new Panel();
     p1.add(label1,"West");
     p1.add(text1,"Center");
     p2.add(label2,"West");
     p2.add(choice,"Center");
     p3.add(label3,"West");
     p3.add(text2,"Center");
     p4.add(label4,"West");
     p4.add(text3,"Center");
     p5.add(label5,"West");
     p5.add(text4,"Center");
     p6.add(button1,"West");
     p6.add(button2,"Center");
     p7.add(p1,"North");
     p7.add(p2,"Center");
     p7.add(p3,"South");
     p8.add(p4,"North");
     p8.add(p5,"Center");
     p8.add(p6,"South");
     p9.add(p7,"North");
     p9.add(p8,"Center");
     add(p9);
     addWindowListener (new WindowAdapter()
       {public void windowClosing(WindowEvent e)
          {dispose();}
       }
    );
    try
    { tianjiakecheng();
    }
    catch(SQLException e8) {}
   }

     public void tianjiakecheng() throws SQLException
     { try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      rs=sql.executeQuery("select 课程名 from kecheng");
      while(rs.next())
      {String qq=rs.getString("课程名");
       choice.add(qq);
      }
      con.close();
      }
      
      public void itemStateChanged(ItemEvent e) 
      { try
        {qq();
        }
        catch(SQLException e7) {}
      }
      public void qq() throws SQLException
     { String s1="'"+choice.getSelectedItem()+"'";
      try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      rs=sql.executeQuery("select * from kecheng where 课程名="+s1);
      while(rs.next())
      {String q1=rs.getString("课程号");
       String q2=rs.getString("教师");
       String q3=rs.getString("学时");
       String q4=rs.getString("上课地点");
      text1.setText(q1);
      text2.setText(q2);
      text3.setText(q3);
      text4.setText(q4);
      con.close();
      }
     } 
      public void actionPerformed(ActionEvent e)
      {if(e.getSource()==button1)
       {try
        {xuanke();
        }
        catch(SQLException e3) {}
       }
       else if(e.getSource()==button2)
       {try
        {tuixuan();
        }
        catch(SQLException e6) {}
       }
      }
      public void xuanke() throws SQLException
      { try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
       catch(ClassNotFoundException e2) {}
       con=DriverManager.getConnection("jdbc:odbc:qqq","","");
       sql=con.createStatement();
       String q1="'"+text1.getText().trim()+"'";
       String q2="'"+choice.getSelectedItem().trim()+"'";
       rs=sql.executeQuery("select * from xuanke where 课程号="+q1+" and 用户名="+xuehao);
       while(rs.next())
       {JOptionPane.showMessageDialog(this,"你已经选过此门课了!","提示",JOptionPane.WARNING_MESSAGE);
        return; 
       }
       sql.executeUpdate("insert into xuanke values("+xuehao+","+q1+","+q2+")");
      JOptionPane.showMessageDialog(this,"选课成功","提示",JOptionPane.WARNING_MESSAGE); 
      con.close();  
      }
      public void tuixuan() throws SQLException
      {String q1="'"+text1.getText().trim()+"'";
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
       catch(ClassNotFoundException e2) {}
       con=DriverManager.getConnection("jdbc:odbc:qqq","","");
       sql=con.createStatement();
       rs=sql.executeQuery("select * from xuanke where 课程号="+q1 );
       while(rs.next())
       {sql.executeUpdate("delete from xuanke where 用户名="+xuehao+" and 课程号="+q1);
         JOptionPane.showMessageDialog(this,"退选成功","提示",JOptionPane.WARNING_MESSAGE); 
         con.close();
         return;
       }
       JOptionPane.showMessageDialog(this,"你没有选修这门课","提示",JOptionPane.WARNING_MESSAGE);        
      }
   }
   class chaxunxuankexinxi  extends Frame implements ActionListener
   {
     Label label1,label2,label3,label4;
     TextField text1,text2,text3;
     Choice choice;
     Button button1,button2;
     Connection con=null;
     Statement sql=null;
     ResultSet rs=null;
     int num;
     chaxunxuankexinxi()
    {super("选课信息查询页面");
     setBackground(color);
     setSize(400,400);
     setBounds(200,200,800,300);
     setVisible(false);
     label1=new Label("已选修的课程名");
     label2=new Label("教师");
     label3=new Label("学时");
     label4=new Label("上课地点");
     choice=new Choice();
     text1=new TextField(10);
     text2=new TextField(10);
     text3=new TextField(10);
     button1=new Button("查询");
     button2=new Button("查询全部选修课程的信息");
     button1.addActionListener(this);
     button2.addActionListener(this);
     Panel p1=new Panel();
     Panel p2=new Panel();
     Panel p3=new Panel();
     Panel p4=new Panel();
     Panel p5=new Panel();
     Panel p7=new Panel();
     Panel p8=new Panel();
     Panel p9=new Panel();
     p1.add(label1,"West");
     p1.add(choice,"Center");
     p2.add(label2,"West");
     p2.add(text1,"Center");
     p3.add(label3,"West");
     p3.add(text2,"Center");
     p4.add(label4,"West");
     p4.add(text3,"Center");
     p5.add(button1,"West");
     p5.add(button2,"Center");
     p7.add(p1,"West");
     p7.add(p2,"Center");
     p7.add(p3,"East");
     p7.add(p4,"South");
     p8.add(p5,"Center");
     p9.add(p7,"North");
     p9.add(p8,"Center"); 
     add(p9);
     addWindowListener (new WindowAdapter()
       {public void windowClosing(WindowEvent e)
          {dispose();}
       }
    );
    validate();
    try
    { tianjiakecheng();
    }
    catch(SQLException e8) {}
   }

     public void tianjiakecheng() throws SQLException
     { try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
      catch(ClassNotFoundException e2) {}
      con=DriverManager.getConnection("jdbc:odbc:qqq","","");
      sql=con.createStatement();
      rs=sql.executeQuery("select 课程名 from xuanke where 用户名="+xuehao);
      while(rs.next())
      {String qq=rs.getString("课程名");
       choice.add(qq);
      }
      num=choice.getItemCount();
      con.close();
      }
      
      public void actionPerformed(ActionEvent e)
      {if(e.getSource()==button1)
       {try
        {chaxun();
        }
        catch(SQLException e4) {}
        }
        else if(e.getSource()==button2)
        {setVisible(false);
         chaxunsuoyouxuanke jj=new chaxunsuoyouxuanke();
         jj.setVisible(true);
        }
       }
       public void chaxun() throws SQLException
       {try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
        catch(ClassNotFoundException e2) {}
        con=DriverManager.getConnection("jdbc:odbc:qqq","","");
        sql=con.createStatement();
        String qq="'"+choice.getSelectedItem()+"'";
        rs=sql.executeQuery("select * from kecheng where 课程名="+qq);
        while(rs.next())
        {String q1=rs.getString("教师");
         String q2=rs.getString("学时");
         String q3=rs.getString("上课地点");
         text1.setText(q1);
         text2.setText(q2);
         text3.setText(q3);
        }
       }
        class chaxunsuoyouxuanke extends JFrame 
       {Object a[][];
        Object columnName[]={"课程名","教师","学时","上课地点"};
        JTable table;
        Container container;
        String kechengming,jiaoshi,xueshi,shangkedidian;
        Connection con;
        Statement sql;
        ResultSet rs;
        chaxunsuoyouxuanke()
        {super("查询所有");
        a=new Object[num][4];
		table=new JTable(a,columnName);
		setSize(500,500);
		setBounds(200,200,500,300);
		setVisible(false);
		addWindowListener (new WindowAdapter()
        {public void windowClosing(WindowEvent e)
          {setVisible(false);}
        }
        );
        container=getContentPane();
        container.add(new JScrollPane(table),BorderLayout.CENTER);
        container.add(new Label("你选修了"+num+"门课程"),BorderLayout.SOUTH);
        try
        {chaxun();
        }
        catch(SQLException e6) {}
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -