java-Mysql学生管理系统

Window1//主方法
package stu_zizhu1;

import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Window1 {
public static void main(String[] args) {
JFrame jf=new JFrame("学生管理系统");

    JButton b1=new JButton("添加");
    JButton b2=new JButton("查找");
    JButton b3=new JButton("修改");
    JButton b4=new JButton("删除");
    JButton b5=new JButton("浏览");
    FlowLayout flow = new FlowLayout(FlowLayout.LEFT,10,10);
    JPanel jp=new JPanel(flow);
    jp.add(b1);
    jp.add(b2);
    jp.add(b3);
    jp.add(b4);
    jp.add(b5);
    
    jf.add(jp);
     
    jp.setBackground(Color.red);
    jf.setSize(500,500);
    jf.setLocation(500,500);
    jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jf.setVisible(true);
    
    b1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Add1 a1=new Add1();
        }
    });
    b2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Find1 find1=new Find1();
        }
    });
    b3.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Modify1 modify1=new Modify1();
        }
    });
    b4.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Delete1 delete1=new Delete1();
        }
    });
    b5.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Look1 look1=new Look1();
        }
    });

}
    

}

package stu_zizhu1;

import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

public class Add1 extends JFrame{

//定义标签
JLabel jlid=new JLabel("ID:");
JLabel jlname=new JLabel("Name:");
JLabel jlage=new JLabel("Age:");
JLabel jlsex=new JLabel("Sex:");
JLabel jlscore=new JLabel("Score:");
JLabel jlbirthday=new JLabel("Birthday:");
//定义文本框

JTextField jfid=new JTextField("",20);
JTextField jfname=new JTextField("",20);
JTextField jfage=new JTextField("",20);
JTextField jfsex=new JTextField("",20);
JTextField jfscore=new JTextField("",20);
JTextField jfbirthday=new JTextField("",20);

//定义按钮(本人再次严重犯错JButton被我写成Button 真的是头疼)
JButton tianjia=new JButton("添加");
JButton chongzhi =new JButton("重置");
JButton fanhui=new JButton("返回");

public  Add1() {
    //定义面板
    
    //jpid面板添加标签(jlid)&&文本框(jfid)
    JPanel jpid=new JPanel();
    jpid.add(jlid);
    jpid.add(jfid);
    
    JPanel jpname=new JPanel();
    jpname.add(jlname);
    jpname.add(jfname);
    
    JPanel jpage=new JPanel();
    jpage.add(jlage);
    jpage.add(jfage);
    
    JPanel jpsex=new JPanel();
    jpsex.add(jlsex);
    jpsex.add(jfsex);
    
    JPanel jpscore=new JPanel();
    jpscore.add(jlscore);
    jpscore.add(jfscore);
    
    JPanel jpbirthday=new JPanel();
    jpbirthday.add(jlbirthday);
    jpbirthday.add(jfbirthday);
    
    JPanel jpbutton=new JPanel(new GridLayout(1,3));
    jpbutton.add(tianjia);
    jpbutton.add(chongzhi);
    jpbutton.add(fanhui);
    
    //按钮添加监听器
    tianjia.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Connection conn=null;
            PreparedStatement prestat=null;
            Statement stat =null;
            String sql ="insert into student1(id,name,age,sex,score,birthday) "+"values(?,?,?,?,?,?)";//少加一个问好?
            try{
                Class.forName("Driver");
                System.out.println("JBDC 加载成功!");
            }catch(Exception a){
                System.out.println("JBDC 狗带!");
                a.printStackTrace();
            }
            try {
                conn= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
                prestat=(PreparedStatement) conn.prepareStatement(sql);
                
                prestat.setString(1,jfid.getText());
                prestat.setString(2,jfname.getText());
                prestat.setString(3,jfage.getText());
                prestat.setString(4,jfsex.getText());
                prestat.setString(5,jfscore.getText());
                prestat.setString(6,jfbirthday.getText());
                
                prestat.executeUpdate();
            } catch (SQLException s) {
                // TODO Auto-generated catch block
                s.printStackTrace();
            }finally {
                try {
                    conn.close();
                } catch (SQLException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
            
        }
        
    });
    fanhui.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Window1 window1=new Window1();
        }
        
    });
    chongzhi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jfid.setText("");
            jfname.setText("");
            jfage.setText("");
            jfsex.setText("");
            jfscore.setText("");
            jfbirthday.setText("");
            
        }
        
    });


    this.setTitle("添加学生信息");
    this.setLayout(new GridLayout(9,1));
    this.add(jpid);
    this.add(jpname);
    this.add(jpage);
    this.add(jpsex);
    this.add(jpscore);
    this.add(jpbirthday);
    this.add(jpbutton);
    this.setLocation(400,300);
    this.setSize(350,300);
    this.setVisible(true);
    
}

}
package stu_zizhu1;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class Find1 extends JFrame{
JLabel jlid=new JLabel("ID:");
JTextField jtfid=new JTextField("",20);

JLabel jlname=new JLabel("Name:");
JLabel jlage=new JLabel("Age:");
JLabel jlsex=new JLabel("Sex:");
JLabel jlscore=new JLabel("Score:");
JLabel jlbirthday=new JLabel("Birthday:");


//JLabel jid=new JLabel();
JLabel jname=new JLabel();
JLabel jage=new JLabel();
JLabel jsex=new JLabel();
JLabel jscore=new JLabel();
JLabel jbirthday=new JLabel();
//此处按钮一定要设置成JButton
JButton query=new JButton("查询");
JButton ret=new JButton("返回");
//此处不可有void
    public   Find1() {
    JPanel jpid=new JPanel();
    jpid.add(jlid);
    jpid.add(jtfid);
    
    JPanel jpname=new JPanel();
    jpname.add(jlname);
    jpname.add(jname);
    
    JPanel jpage=new JPanel();
    jpage.add(jlage);
    jpage.add(jage);
    
    JPanel jpsex=new JPanel();
    jpsex.add(jlsex);
    jpsex.add(jsex);
    
    JPanel jpscore=new JPanel();
    jpscore.add(jlscore);
    jpscore.add(jscore);
    
    JPanel jpbirthday=new JPanel();
    jpbirthday.add(jlbirthday);
    jpbirthday.add(jbirthday);
    
    JPanel button1=new JPanel(new GridLayout(1,1));
    button1.add(query);
    button1.add(ret);
    
    query.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e1) {
            Connection conn=null;
            Statement state=null;
            ResultSet res=null;
            //此处犯错 忘记写id
            String sql="select id,name,age,sex,score,birthday from student1;";
            try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                System.out.println("123");
                e.printStackTrace();
            }
            
            try {
                conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
                state=(Statement) conn.createStatement();
                res=state.executeQuery(sql);
                while(res.next()) {
                    if(res.getString(1).equals(jtfid.getText())) {
                        jname.setText(res.getString(2));
                        jage.setText(res.getString(3));
                        jsex.setText(res.getString(4));
                        jscore.setText(res.getString(5));
                        jbirthday.setText(res.getString(6));
                        
                    }
                }
            } catch (SQLException e) {
                System.out.println("1234");
                e.printStackTrace();
            }finally {
                try {
                    conn.close();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        
    });
    
    ret.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Window1 window1=new Window1();
            
        }
        
    });
    this.setTitle("学生查询系统 ");
    this.setLayout(new GridLayout(9,1));//9组建
    this.add(jpid);
    this.add(jpname);
    this.add(jpage);
    this.add(jpsex);
    this.add(jpscore);
    this.add(jpbirthday);
    this.add(button1);
    this.setSize(300, 400);
    this.setLocation(300, 400);
    this.setVisible(true);
    
    
    
    
    
}

}
package stu_zizhu1;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class Look1 extends JFrame{
Connection conn =null;
PreparedStatement pre=null;
ResultSet res=null;

JScrollPane jps=null;
Vector columnsname=null;
Vector rowData=null;

public  Look1() {
    JPanel jp1=new JPanel(); 
    jp1.setBackground(Color.gray);
    jp1.setSize(500, 500);
    JLabel jb=new JLabel("欢迎使用学生管理系统");
    jb.setBounds(0, 0, 50, 50);
    jp1.add(jb);
    
    
    JPanel jp=new JPanel();
    //JLabel jb1=new JLabel("欢迎使用学生管理系统");
    jp.setSize(400, 400);
    jp.setBackground(Color.green);
    //jp.add(jb1);
    jp.add(jp1);
    //定义列名
    columnsname=new Vector();
    columnsname.add("id");
    columnsname.add("name");
    columnsname.add("age");
    columnsname.add("sex");
    columnsname.add("score");
    columnsname.add("birthday");
    rowData =new Vector();
    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
        pre=(PreparedStatement) conn.prepareStatement("select *from student1");
        res=pre.executeQuery();
        while(res.next()) {
            Vector hang =new Vector();
            hang.add(res.getString(1));
            hang.add(res.getString(2));
            hang.add(res.getString(3));
            hang.add(res.getString(4));
            hang.add(res.getString(5));
            hang.add(res.getString(6));
            rowData.add(hang);
            
        }
        System.out.println("load  ok!");
    } catch (Exception e) {
        System.out.println("go die");
        e.printStackTrace();
    }finally {
        try {
            res.close();
            pre.close();
            conn.close();
            System.out.println("close ok");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    JTable jtable=new JTable(rowData,columnsname);
    jps=new JScrollPane(jtable);
    
    this.add(jps);
    this.setTitle("学生浏览系统");
    this.setLayout(new GridLayout(3,4));
    
    this.add(jp);
    
    
    this.setSize(400, 500);
    this.setLocation(300,400);
    this.setVisible(true);
    this.setResizable(false);
    
}

}
package stu_zizhu1;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

import First.Window;

public class Modify1 extends JFrame{
//定义标签
JLabel jlid=new JLabel("ID:");
JLabel jlname=new JLabel("Name:");
JLabel jlage=new JLabel("Age:");
JLabel jlsex=new JLabel("Sex:");
JLabel jlscore=new JLabel("Score:");
JLabel jlbirthday=new JLabel("Birthday:");
//定义文本框

JTextField jfid=new JTextField("",20);
JTextField jfname=new JTextField("",20);
JTextField jfage=new JTextField("",20);
JTextField jfsex=new JTextField("",20);
JTextField jfscore=new JTextField("",20);
JTextField jfbirthday=new JTextField("",20);

//定义按钮(本人再次严重犯错JButton被我写成Button 真的是头疼)
JButton change=new JButton("修改");
JButton chongzhi =new JButton("重置");
JButton fanhui=new JButton("返回");

public  Modify1() {
    //定义面板

    //jpid面板添加标签(jlid)&&文本框(jfid)
    JPanel jpid=new JPanel();
    jpid.add(jlid);
    jpid.add(jfid);

    JPanel jpname=new JPanel();
    jpname.add(jlname);
    jpname.add(jfname);

    JPanel jpage=new JPanel();
    jpage.add(jlage);
    jpage.add(jfage);

    JPanel jpsex=new JPanel();
    jpsex.add(jlsex);
    jpsex.add(jfsex);

    JPanel jpscore=new JPanel();
    jpscore.add(jlscore);
    jpscore.add(jfscore);

    JPanel jpbirthday=new JPanel();
    jpbirthday.add(jlbirthday);
    jpbirthday.add(jfbirthday);

    JPanel jpbutton=new JPanel(new GridLayout(1,3));
    jpbutton.add(change);
    jpbutton.add(chongzhi);
    jpbutton.add(fanhui);
    change.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            //String id1=jfid.getText();
            String name1=jfname.getText();//此处犯错
            String age1=jfage.getText();
            String sex1=jfsex.getText();
            String score1=jfscore.getText();
            String birthday1=jfbirthday.getText();
            
            Connection conn=null;
            Statement state=null;

// PreparedStatement prestate=null;
ResultSet res=null;

            String sql="select id,name,age,sex,score,birthday from student1;";
            
            try{
                Class.forName("com.mysql.jdbc.Driver");
                
            }catch(Exception d){
                System.out.println("jdbc fall");
                d.printStackTrace();
            }
            try{
                conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
                state=(Statement) conn.createStatement();
                res=state.executeQuery(sql);
                while (res.next())
                {
                    //change
                    if (res.getString(1).equals(jfid.getText()))
                    {
                    try{
                        Class.forName("com.mysql.jdbc.Driver");
                    }catch(Exception d){
                        System.out.println("jdbc fall");
                        d.printStackTrace();
                    }
                        String sql1="update student1 set name='"+name1+"'where id='"+jfid.getText()+"'";
                        String sql2="update student1 set age='"+age1+"'where id='"+jfid.getText()+"'";
                        String sql3="update student1 set sex='"+sex1+"'where id='"+jfid.getText()+"'";
                        String sql4="update student1 set score='"+score1+"'where id='"+jfid.getText()+"'";
                        String sql5="update student1 set birthday='"+birthday1+"'where id='"+jfid.getText()+"'";
                        try {
                            conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");
                            state=(Statement) conn.createStatement();
                            state.execute(sql1);
                            state.execute(sql2);
                            state.execute(sql3);
                            state.execute(sql4);
                            state.execute(sql5);
                        } catch (SQLException g) {
                            // TODO Auto-generated catch block
                            g.printStackTrace();
                        }try{
                            state.close();
                            conn.close();
                        }catch(SQLException ar){
                            ar.printStackTrace();
                    }

                        break;
                    }
                    
                //change end
                }
            }catch (SQLException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            
            
        }
            finally{
                try{
                    conn.close();
                }catch(SQLException ar){
                    ar.printStackTrace();
                }
        
            }
            



        }

    });
    fanhui.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
            Window window = new Window();           
        }           
    });
    chongzhi.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jfid.setText("");
            jfname.setText("");
            jfage.setText("");
            jfsex.setText("");
            jfscore.setText("");
            jfbirthday.setText("");

        }

    });
    this.setTitle("修改学生信息");
    this.setLayout(new GridLayout(9,1));
    this.add(jpid);
    this.add(jpname);
    this.add(jpage);
    this.add(jpsex);
    this.add(jpscore);
    this.add(jpbirthday);
    this.add(jpbutton);
    this.setLocation(400,300);
    this.setSize(350,300);
    this.setVisible(true);

}

}

转载于:https://www.cnblogs.com/Pythons/p/10932308.html

压缩包含使用说明,windows端在文件资源管理器中 点击create.bat支持一键建表,其他系统可以使用 createtables.sql里面的sql语句进行数据库 欢迎使用学生信息管理系统(管理员端) 本系统支持添加,删除,修改等实用功能 方便您更好的管理学生数据 【I】管理员端 一,选择数据库 通过右上角的数据库菜单栏可以选择当前操 作的数据库 二,添加教师,学生,教师,学生成绩(管理员) 1)通过管理员窗口的左侧按钮可以按需添加 学生,教师,管理员,学生成绩等信息 2)通过下方按钮“添加行”来新建空行,然 后手动输入数据,再点击“保存”按钮将表 单上传到数据库。 (注意:如果格式不正确,比如通过该方法上传 的数据可能会发生错误,所以方法2只适合管 理员使用) 3)支持批量添加行(注意:如果有一行错误,所 有操作将被回滚) 4)为学生添加老师,进入选择学生数据库,在 某一个学生行单击右键,选择“添加老师”,即 可为该id的学生添加老师 5)为学生添加课程,进入学生数据可以,在某一 学生行单击右键,选择“修改成绩”,可以进入 成绩修改窗口(管理员端),输入学生id, 为学生添加任意课程,也可为课程添加或修改删除 成绩 三,删除 在表格中使用鼠标选中一些数据行,然后点击 左侧“删除”按钮,即可删除表单中的数据 四,修改 双击表格,输入数据,按回车保存,然后点击 右下角“保存修改”按钮,将表单上传到数据 库中。(注意:因为学生成绩信息是以二进制 形式储存,所以请不要直接在表格中修改) 五,排序 在表格某一列点击排序按钮,对当前选择的表单 按该列进行排序,右上角排序选择框可以决定排 序的方向是升序还是逆序。 【II】教师端 1)教师基本信息 教师信息将显示在表格左侧 2)查看学生列表 单击“我的学生”,表格中将显示该教师的所有 学生 3)在表格中右击某一个学生,将进入成绩修改窗 口(教师端),支持为当前学生添加或修改当前 教师所教科目的学生成绩 4)查看成绩表 单击“成绩表”,表格中显示该教师所有学生的 成绩信息。 【III】学生端 1)学生基本信息 学生信息将显示在表格左侧 2)查看成绩 单击“学业成绩”,表格中将显示学生所有成绩 3)查看老师 单击“我的老师”,表格中将显示学生所有老师 的基本信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值