学生学籍管理系统_学生登陆系统查询与修改信息

来源:互联网 发布:淘宝的牛头301敢买吗 编辑:程序博客网 时间:2024/04/30 21:29

 SCx.java

package studentManage;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class SCx extends JFrame implements ActionListener {static SCx s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField("");static JLabel label3 = new JLabel("班级:");static JTextField textField3= new JTextField("");static JLabel label4 = new JLabel("专业:");static JTextField textField4 = new JTextField("");static JLabel label5 = new JLabel("院系:");static JTextField textField5 = new JTextField("");static JLabel label6 = new JLabel("性别");static JTextField textField6 = new JTextField("");static JLabel label7 = new JLabel("年级:");static JTextField textField7 = new JTextField("");static JLabel label8 = new JLabel("生日");static JTextField textField8 = new JTextField("");static JLabel label9 = new JLabel("电话:");static JTextField textField9 = new JTextField("");static JLabel label10 = new JLabel("QQ:");static JTextField textField10 = new JTextField("");static JLabel label11 = new JLabel("状态:");static JTextField textField11 = new JTextField("");static JLabel label12 = new JLabel("密码:");static JTextField textField12 = new JTextField("");static JButton button3 = new JButton("查询");static JButton button4 = new JButton("修改");//初始化界面public SCx() throws Exception {this.setTitle("查询学生信息");this.setLayout(null);this.setSize(600, 600);label1.setBounds(30, 11, 50, 30);//学号textField1.setBounds(60, 16, 70, 20);label2.setBounds(160, 11, 50, 30);//姓名textField2.setBounds(190, 16, 70, 20);label3.setBounds(290, 11, 50, 30);//班级textField3.setBounds(320, 16, 70, 20);//===========label4.setBounds(30, 61, 50, 30);//专业textField4.setBounds(60, 66, 70, 20);label5.setBounds(160, 61, 50, 30);//系别textField5.setBounds(190, 66, 70, 20);label6.setBounds(290, 61,50, 30);//性别textField6.setBounds(320, 66, 70, 20);//===========label7.setBounds(30, 111, 50, 30);//年级textField7.setBounds(60, 116, 70, 20);label8.setBounds(140, 111, 50, 30);//出生日期textField8.setBounds(190, 116, 70, 20);label9.setBounds(290, 111, 50, 30);//电话textField9.setBounds(320, 116, 70, 20);//=========label10.setBounds(30, 161, 50, 30);//QQtextField10.setBounds(60,166,70,20 );label11.setBounds(160, 161, 50, 30);//状态textField11.setBounds(190,166, 70, 20);label12.setBounds(290, 161, 51, 33);//密码textField12.setBounds(320,166, 70, 22);button3.setBounds(150, 241, 80, 33);button4.setBounds(250, 241, 80, 33);button3.addActionListener(this);button4.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(label9);this.add(label10);this.add(label11);this.add(label12);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField6);this.add(textField7);this.add(textField8);this.add(textField9);this.add(textField10);this.add(textField11);this.add(textField12);this.add(button3);this.add(button4);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception {SCx a = new SCx();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e) {if (e.getSource() == button3) {try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException ce) {JOptionPane.showMessageDialog(s, ce.getMessage());}try {Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from infor where stuId='"+ textField1.getText() + "'");if (textField1.getText().trim().equals("")) {JOptionPane.showMessageDialog(this, "学号不可为空!");}else if (rs.next()) {textField1.setText(rs.getString("stuId"));textField2.setText(rs.getString("name"));textField3.setText(rs.getString("class"));textField4.setText(rs.getString("profess"));textField5.setText(rs.getString("depart"));textField6.setText(rs.getString("sex"));textField7.setText(rs.getString("grade"));textField8.setText(rs.getString("bir"));textField9.setText(rs.getString("phone"));textField10.setText(rs.getString("QQ"));textField11.setText(rs.getString("state"));textField12.setText(rs.getString("password"));} else {JOptionPane.showMessageDialog(this, "无此记录!!!");}}catch (SQLException se) {JOptionPane.showMessageDialog(s, se.getMessage());}}if(e.getSource()==button4)    {try{Class.forName("com.mysql.jdbc.Driver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");Statement stmt = con.createStatement();     ResultSet rs=stmt.executeQuery("select * from infor where stuId='"+textField1.getText()+"'");                if(textField1.getText().trim().equals(""))                {                    JOptionPane.showMessageDialog(this,"学号不可为空!");                }else if(rs.next())               {                              try{                stmt.execute("update infor set name='"+                         textField2.getText()+"',class='"+textField3.getText()+"',profess='"+                                textField4.getText()+"',depart='"+textField5.getText()+"',sex='"+                                textField6.getText()+"',grade='"+textField7.getText()+"',bir='"+                                textField8.getText()+ "',phone='"+textField9.getText()+"',QQ='"+textField10.getText()+                                "',state='"+textField11.getText()+"',password='"+textField12.getText()                             +"'where stuId='"+textField1.getText                          ()+"'");                                JOptionPane.showMessageDialog(null,"修改成功");                                   }                                                               //stmt.executeQuery(updateSql);}                            // stmt.executeUpdate(updateSql);}                                catch(SQLException se)                                {                                //JOptionPane.showMessageDialog(null,"请输入正确的信息");                                JOptionPane.showMessageDialog(s,se.getMessage());                                                                }                                                                     }                        }      catch(SQLException se)        {           JOptionPane.showMessageDialog(s,se.getMessage());          }    }}}

SInterface.java

package studentManage;import java.awt.*;import java.awt.event.*;import javax.swing.*;/* * 学生登录 * 操作界面接口类,可以直接扩展、调用。 */public class SInterface extends JFrame implements ActionListener {static JMenuBar jMenuBar = new JMenuBar();// 菜单条static JMenu jMenuFile = new JMenu("文件");// 菜单项static JMenu jMenuExit = new JMenu("退出");//static JMenuItem jMenuItem1 = new JMenuItem("添加信息");// 菜单子项static JMenuItem jMenuItem2 = new JMenuItem("修改信息");static JMenuItem jMenuItem3 = new JMenuItem("信息查询");//static JMenuItem jMenuItem4 = new JMenuItem("删除信息");static JLabel label3 = new JLabel("请选择操作项");static JLabel label4 = new JLabel("学籍管理系统");//static JButton button2 = new JButton("添加信息");static JButton button3 = new JButton("修改信息");static JButton button4 = new JButton("信息查询");//static JButton button5 = new JButton("删除信息");public SInterface() {this.setTitle("学籍管理系统");this.setLayout(null);this.setSize(400, 400);label3.setBounds(158, 92, 98, 33);label3.setFont(new Font("Dialog", Font.PLAIN, 15));label4.setFont(new Font("Dialog", Font.BOLD, 20));label4.setBounds(157, 37, 280, 40);//button2.setBounds(74, 136, 97, 33);button3.setBounds(226, 136, 97, 33);//修改信息button4.setBounds(74, 136, 97, 33);//信息查询//button5.setBounds(226, 185, 97, 33);//this.add(button2);this.add(button3);this.add(button4);//this.add(button5);this.add(label3);this.add(label4);setJMenuBar(jMenuBar);//jMenuFile.add(jMenuItem1);// ”文件“菜单项中加入子菜单jMenuFile.add(jMenuItem2);jMenuFile.add(jMenuItem3);//jMenuFile.add(jMenuItem4);jMenuBar.add(jMenuFile);// 将菜单项加入菜单条jMenuBar.add(jMenuExit);//button2.addActionListener(this);// 本窗口向按钮事件源注册button3.addActionListener(this);button4.addActionListener(this);//button5.addActionListener(this);//jMenuItem1.addActionListener(this);// 本窗口菜单子项注册jMenuItem2.addActionListener(this);jMenuItem3.addActionListener(this);//jMenuItem4.addActionListener(this);jMenuExit.addActionListener(this);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) {SInterface a = new SInterface();}public void actionPerformed(ActionEvent e) // 按钮事件的处理{if (e.getSource() == jMenuExit) {System.exit(0);}   if (e.getSource() == jMenuItem3 || e.getSource() == button4) {try {SCx a = new SCx();} catch (Exception ec) {}} }}

SXg.java

package studentManage;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.sql.*;public class SXg extends JFrame implements ActionListener {static SXg s;static JLabel label1 = new JLabel("学号:");static JTextField textField1 = new JTextField("");static JLabel label2 = new JLabel("姓名:");static JTextField textField2 = new JTextField("");static JLabel label3 = new JLabel("性别:");static JTextField textField7 = new JTextField("");static JLabel label4 = new JLabel("出生日期:");static JTextField textField3 = new JTextField("");static JLabel label5 = new JLabel("政治面貌:");static JTextField textField8 = new JTextField("");static JLabel label6 = new JLabel("籍贯");static JTextField textField4 = new JTextField("");static JLabel label7 = new JLabel("系别:");static JTextField textField9 = new JTextField("");static JLabel label8 = new JLabel("专业:");static JTextField textField5 = new JTextField("");static JButton button2 = new JButton("修改");public SXg() {this.setTitle("修改学生信息");this.setLayout(null);this.setSize(400, 400);label1.setBounds(30, 11, 51, 33);textField1.setBounds(86, 16, 74, 22);label2.setBounds(162, 11, 51, 33);textField2.setBounds(192, 16, 44, 22);label3.setBounds(241, 11, 70, 33);textField7.setBounds(275, 15, 50, 25);label4.setBounds(31, 53, 55, 33);textField3.setBounds(86, 58, 74, 22);label5.setBounds(241, 53, 70, 33);textField8.setBounds(296, 57, 72, 25);label6.setBounds(163, 53, 26, 33);textField4.setBounds(191, 58, 44, 22);label7.setBounds(30, 94, 50, 33);textField9.setBounds(86, 94, 74, 22);label8.setBounds(163, 94, 51, 33);textField5.setBounds(190, 99, 178, 22);button2.setBounds(115, 241, 80, 33);button2.addActionListener(this);this.add(label1);this.add(label2);this.add(label3);this.add(label4);this.add(label5);this.add(label6);this.add(label7);this.add(label8);this.add(textField1);this.add(textField2);this.add(textField3);this.add(textField4);this.add(textField5);this.add(textField7);this.add(textField8);this.add(textField9);this.add(button2);this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);this.setVisible(true);}public static void main(String[] args) throws Exception {SXg a = new SXg();a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e)//事件处理程序   {    if(e.getSource()==button2)    {try{Class.forName("com.mysql.jdbc.Driver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/stu","root","111");Statement stmt = con.createStatement();     ResultSet rs=stmt.executeQuery("select * from infor where stuId='"+textField1.getText()+"'");                if(textField1.getText().trim().equals(""))                {                    JOptionPane.showMessageDialog(this,"学号不可为空!");                }else if(rs.next())               {                              try{                stmt.execute("update infor set stuId='"+textField1.getText()+"',name='"+                         textField2.getText()+"',sex='"+textField7.getText()+"',birDate='"+                                textField3.getText()+"',look='"+textField8.getText()+"',jiGuan='"+                                textField4.getText()+"',xiBie='"+textField9.getText()+"',zhuanYe='"+                                textField5.getText()+ "'");                                JOptionPane.showMessageDialog(null,"修改成功");                                   }                                                               //stmt.executeQuery(updateSql);}                            // stmt.executeUpdate(updateSql);}                                catch(SQLException se)                                {                                //JOptionPane.showMessageDialog(null,"请输入正确的信息");                                JOptionPane.showMessageDialog(s,se.getMessage());                                                                }                                                                     }                        }      catch(SQLException se)        {           JOptionPane.showMessageDialog(s,se.getMessage());          }    }              }}




0 0