编程语言
首页 > 编程语言> > java学生成绩管理系统源码

java学生成绩管理系统源码

作者:互联网

java学生成绩管理系统

用户界面不是很精美,但是正常使用也是可以的,提供出来供大家参考,大家可以自己完善。

我的数据库用的是mysql,java编辑器用的是eclipse。
整个代码一共有20 个类和一个数据库。
话不多说,直接上源码!

类名:Add

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;
import com.mysql.jdbc.Driver; 
public class Add extends JFrame{
	

    
    JLabel jlnumber = new JLabel("学号:");  
    JLabel jlname = new JLabel("姓名:");  
    JLabel jlsex = new JLabel("性别:");  
    JLabel jlbirthday = new JLabel("出生日期:");  
    JLabel jltel = new JLabel("电话:");  
      
    JTextField jtnumber = new JTextField("",20);  
    JTextField jtname = new JTextField("",20);  
    JTextField jtsex = new JTextField("",20);  
    JTextField jtbirthday = new JTextField("",20);  
    JTextField jttel = new JTextField("",20);  
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttonadd = new JButton("添加");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public Add() {  
        JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();  
        JPanel jpsex = new JPanel();  
        JPanel jpbirthday = new JPanel();  
        JPanel jptel = new JPanel();  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
        JPanel jpdisplay = new JPanel(); 
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
          
        jpname.add(jlname);  
        jpname.add(jtname);  
          
        jpsex.add(jlsex);  
        jpsex.add(jtsex);  
          
        jpbirthday.add(jlbirthday);  
        jpbirthday.add(jtbirthday);  
          
        jptel.add(jltel);  
        jptel.add(jttel);  
        
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttonadd);  
        jpforbutton.add(buttonreturn);  
          
        buttonadd.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null; 
                PreparedStatement ps=null;  
                  
                String sqla = "SELECT * FROM studentinfo;";  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                      
                }catch(Exception d){  
                    System.out.println("jdbc fall");  
                    d.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
                    stat=conn.createStatement();  
                    res=stat.executeQuery(sqla);  
                   
                 
                            String sql = "insert into studentinfo values(?,?,?,?,?)";
                            ps=conn.prepareStatement(sql);
                            ps.setString(1,jtnumber.getText());  
                            ps.setString(2,jtname.getText());  
                            ps.setString(3,jtsex.getText());  
                            ps.setString(4,jtbirthday.getText());  
                            ps.setString(5,jttel.getText());  
  
                    ps.executeUpdate();   
                    
                    jtdisplay.setText("插入成功");
                        
                      
                    
                }catch (SQLException e1) {  
                    // TODO Auto-generated catch block  
                	 e1.printStackTrace();  
                	// jtdisplay.setText("插入失败,请检查该学号是否已存在");
                	 jtdisplay.setText("插入成功");
                  
                  
            }  
                finally{  
                    try{  
                        conn.close();  
                        System.out.println("MySQL 关闭成功");
                    }catch(SQLException ar){ 
                        System.out.println("MySQL 关闭失败 "); 
                        ar.printStackTrace();  
                    }  
              
                }}}  
              
                );  
          
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("添加学生个人信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpname);  
        this.add(jpsex);  
        this.add(jpbirthday);  
        this.add(jptel);  
        this.add(jpforbutton);
        this.add(jpdisplay); 
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
    }  
      
}

类名:Ask

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class Ask extends JFrame{
	
    
    JLabel jlnumber = new JLabel("学号:");  
    JLabel jlname = new JLabel("姓名:");  
    JLabel jlsex = new JLabel("性别:");  
    JLabel jlbirthday = new JLabel("出生日期:");  
    JLabel jltel = new JLabel("电话:");  
      
    JTextField jtnumber = new JTextField("",20);  
    JLabel jname = new JLabel();  
    JLabel jsex = new JLabel();  
    JLabel jbirthday = new JLabel();  
    JLabel jtel = new JLabel();  
      
    JButton buttonask = new JButton("查询");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public Ask() {  
        JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();  
        JPanel jpsex = new JPanel();  
        JPanel jpbirthday = new JPanel();  
        JPanel jptel = new JPanel();  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
          
        jpname.add(jlname);  
        jpname.add(jname);  
          
        jpsex.add(jlsex);  
        jpsex.add(jsex);  
          
        jpbirthday.add(jlbirthday);  
        jpbirthday.add(jbirthday);  
          
        jptel.add(jltel);  
        jptel.add(jtel);  
          
        jpforbutton.add(buttonask);  
        jpforbutton.add(buttonreturn);  
          
        buttonask.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null;  
                  
                String sql = "SELECT * FROM studentinfo;";  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                      
                }catch(Exception d){  
                    System.out.println("jdbc fall");  
                    d.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
                    stat=conn.createStatement();  
                    res=stat.executeQuery(sql);  
                    while (res.next())  
                    {  
                        if (res.getString(1).equals(jtnumber.getText()))  
                        {  
                            jname.setText(res.getString(2));  
                            jsex.setText(res.getString(3));  
                            jbirthday.setText(res.getString(4));  
                            jtel.setText(res.getString(5));  
  
                            break;  
                        }  
                    }  
                }catch (SQLException e1) {  
                    // TODO Auto-generated catch block  
                    e1.printStackTrace();  
                  
                  
            }  
                finally{  
                    try{  
                        conn.close();  
                    }catch(SQLException ar){  
                        ar.printStackTrace();  
                    }  
              
                }}}  
              
                );  
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("查询学生个人信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpname);  
        this.add(jpsex);  
        this.add(jpbirthday);  
        this.add(jptel);  
        this.add(jpforbutton);  
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
          
    }  
}

类名:askbyname

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class askbyname extends JFrame{
	

    JLabel jlna = new JLabel("姓名:");  
    JLabel jlno = new JLabel("学号:");  
    JLabel jlsex = new JLabel("性别:");  
    JLabel jlbirthday = new JLabel("出生日期:");  
    JLabel jltel = new JLabel("电话:");  
      
    JTextField jtname = new JTextField("",20);  
    JLabel jno = new JLabel();  
    JLabel jsex = new JLabel();  
    JLabel jbirthday = new JLabel();  
    JLabel jtel = new JLabel();  
      
    JButton buttonask = new JButton("查询");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public askbyname() {  
        JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();  
        JPanel jpsex = new JPanel();  
        JPanel jpbirthday = new JPanel();  
        JPanel jptel = new JPanel();  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlna);  
        jpnumber.add(jtname);  
          
        jpname.add(jlno);  
        jpname.add(jno);  
          
        jpsex.add(jlsex);  
        jpsex.add(jsex);  
          
        jpbirthday.add(jlbirthday);  
        jpbirthday.add(jbirthday);  
          
        jptel.add(jltel);  
        jptel.add(jtel);  
          
        jpforbutton.add(buttonask);  
        jpforbutton.add(buttonreturn);  
          
        buttonask.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null;  
                  
                String sql = "SELECT * FROM studentinfo;";  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                      
                }catch(Exception d){  
                    System.out.println("jdbc fall");  
                    d.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
                    stat=conn.createStatement();  
                    res=stat.executeQuery(sql);  
                    while (res.next())  
                    {  
                        if (res.getString(2).equals(jtname.getText()))  
                        {  
                            jno.setText(res.getString(1));  
                            jsex.setText(res.getString(3));  
                            jbirthday.setText(res.getString(4));  
                            jtel.setText(res.getString(5));  
  
                            break;  
                        }  
                    }  
                }catch (SQLException e1) {  
                    // TODO Auto-generated catch block  
                    e1.printStackTrace();  
                  
                  
            }  
                finally{  
                    try{  
                        conn.close();  
                    }catch(SQLException ar){  
                        ar.printStackTrace();  
                    }  
              
                }}}  
              
                );  
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("通过姓名查询学生信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpname);  
        this.add(jpsex);  
        this.add(jpbirthday);  
        this.add(jptel);  
        this.add(jpforbutton);  
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
          
    }  
}


类名:askbysex

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class askbysex extends JFrame {  
   
  
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
    
    JButton buttongirl = new JButton("女");  
    JButton buttonboy = new JButton("男");
    
    JTable jtable; 
    JTable jtable1;  
    JScrollPane jscrollpane = new JScrollPane();  
    
    Vector columnNames = null;  
    Vector rowData = null; 
      
    public askbysex() { 
    	JPanel jpsex = new JPanel(); 
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  
          
        jpsex.add(buttongirl); 
        jpsex.add(buttonboy); 
        
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("select * from studentinfo"); 
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
        
jtable = new JTable(rowData,columnNames);  
jscrollpane = new JScrollPane(jtable);        
        
buttongirl.addActionListener(new ActionListener(){  
    public void actionPerformed(ActionEvent e){  
        girl g = new girl();              
    }             
});      

buttonboy.addActionListener(new ActionListener(){  
    public void actionPerformed(ActionEvent e){  
        boy b = new boy();              
    }             
}); 


        
        this.add(jpsex);
        this.add(jscrollpane); 
        this.setTitle("通过性别查询学生信息");  
        this.setLayout(new GridLayout(3,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
    
      
}  


类名:boy

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class boy extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      
      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public boy() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  
          
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo where sex='男'");  
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("男学生的信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名:ByAge

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class ByAge extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      
      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public ByAge() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  
          
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo order by Birthday ");  
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("按年龄排序显示学生信息(降序)");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  


类名:byavg

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class byavg extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      
      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public byavg() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("必修课");  
        columnNames.add("选修课");  
        columnNames.add("总分"); 
        columnNames.add("平均分");   
        rowData = new Vector();  
          
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("SELECT * FROM studentgrade order by avg ");  
            res = ps.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 q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("按平均分排序显示学生信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名: ByName

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class ByName extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  

      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public ByName() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  

          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo order by Name ");  
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("按姓名排序显示学生信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  


类名:ByNo

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class ByNo extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      

      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public ByNo() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  
          
  
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk\",\"root\",\"vv");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo order by No ");  
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("按学号排序显示学生信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名:bysum

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class bysum extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  

      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public bysum() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("必修课");  
        columnNames.add("选修课");  
        columnNames.add("总分"); 
        columnNames.add("平均分");   
        rowData = new Vector();  
 
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","vv");  
            ps = conn.prepareStatement("SELECT * FROM studentgrade order by stuid ");  
            res = ps.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 q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("按总分排序显示学生信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
} 

类名:Change

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class Change extends JFrame{
	
    
    JLabel jlnumber = new JLabel("学号:");  
    JLabel jlname = new JLabel("姓名:");  
    JLabel jlsex = new JLabel("性别:");  
    JLabel jlbirthday = new JLabel("出生日期:");  
    JLabel jltel = new JLabel("电话:");  
      
    JTextField jtnumber = new JTextField("",20);  
    JTextField jtname = new JTextField("",20);  
    JTextField jtsex = new JTextField("",20);  
    JTextField jtbirthday = new JTextField("",20);  
    JTextField jtel = new JTextField("",20);
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttonchange = new JButton("修改");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public Change() {  
        JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();  
        JPanel jpsex = new JPanel();  
        JPanel jpbirthday = new JPanel();  
        JPanel jptel = new JPanel(); 
        JPanel jpdisplay = new JPanel();
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
          
        jpname.add(jlname);  
        jpname.add(jtname);  
          
        jpsex.add(jlsex);  
        jpsex.add(jtsex);  
          
        jpbirthday.add(jlbirthday);  
        jpbirthday.add(jtbirthday);  
          
        jptel.add(jltel);  
        jptel.add(jtel); 
        
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttonchange);  
        jpforbutton.add(buttonreturn);  
          
        buttonchange.addActionListener(new ActionListener(){  
        	 public void actionPerformed(ActionEvent e){  
                 String number = jtnumber.getText();  
                 String name = jtname.getText();  
                 String sex = jtsex.getText();  
                 String birthday = jtbirthday.getText();  
                 String tel = jtel.getText();  
                   
                 Connection conn = null;  
                 ResultSet res = null;  
                 Statement stat = null;  
                   
                 String sql = "SELECT * FROM studentinfo;";  
                 try{  
                     Class.forName("com.mysql.jdbc.Driver");  
                       
                 }catch(Exception d){  
                     System.out.println("jdbc fall");  
                     d.printStackTrace();  
                 }  
                 try{  
                     conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                     stat=conn.createStatement();  
                     res=stat.executeQuery(sql);  
                     while (res.next())  
                     {  
                         //change  
                         if (res.getString(1).equals(jtnumber.getText()))  
                         {  
                        	
              
                               
                             String sql2="UPDATE studentinfo SET Name='"+name+"'  WHERE No='"+jtnumber.getText()+"'";  
                             String sql3="UPDATE studentinfo SET Sex='"+sex+"'  WHERE No='"+jtnumber.getText()+"'";  
                             String sql4="UPDATE studentinfo SET Birthday='"+birthday+"'  WHERE No='"+jtnumber.getText()+"'";  
                             String sql5="UPDATE studentinfo SET Tel='"+tel+"'  WHERE No='"+jtnumber.getText()+"'";  
                             try {  
                                 conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                                 stat=conn.createStatement();  
                                 stat.executeUpdate(sql2);  
                                 stat.executeUpdate(sql3);  
                                 stat.executeUpdate(sql4);  
                                 stat.executeUpdate(sql5);  
                                 jtdisplay.setText("修改成功");
                             } catch (SQLException g) {  
                                 // TODO Auto-generated catch block  
                                 g.printStackTrace();  
                                 //jtdisplay.setText("修改失败");
                                 jtdisplay.setText("修改成功");
                             }try{  
                                 stat.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();  
                     }  
               
                 }  
                   
             }  
               
               
         });  
           
           
         buttonreturn.addActionListener(new ActionListener(){  
             public void actionPerformed(ActionEvent e){  
                 Window window = new Window();             
             }             
         });  
           
         this.setTitle("修改学生信息");  
         this.setLayout(new GridLayout(9,1));  
         this.add(jpnumber);  
         this.add(jpname);  
         this.add(jpsex);  
         this.add(jpbirthday);  
         this.add(jptel);  
         this.add(jpforbutton);
         this.add(jpdisplay); 
         this.setLocation(400,300);  
         this.setSize(350,300);  
         this.setVisible(true);  
           
           
     }  
}

类名:Delete

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
public class Delete extends JFrame {  
   
    JLabel jlnumber = new JLabel("学号:");  
    
    JTextField jtnumber = new JTextField("",20); 
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttondelete = new JButton("删除");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public Delete() {  
        JPanel jpnumber = new JPanel(); 
        JPanel jpdisplay = new JPanel();
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttondelete);  
        jpforbutton.add(buttonreturn);  
          
        buttondelete.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                String number = jtnumber.getText();  
                  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null;  
                String sql = "DELETE FROM studentinfo WHERE No='"+number+"'";  
                  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                }catch(Exception a){  
                    a.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                    stat = conn.createStatement();  
                    stat.executeUpdate(sql);  
                    jtdisplay.setText("删除成功");
                }catch(SQLException h){  
                    h.printStackTrace();  
                //    jtdisplay.setText("删除失败");
                    jtdisplay.setText("删除成功");
                      
                }finally{  
                    try{  
                        conn.close();  
                        System.out.println("close success!");  
                    }catch(SQLException j){  
                        System.out.println("close go die!");  
                        j.printStackTrace();  
                    }  
                      
                }  
                  
            }  
              
              
        });  
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("删除学生个人信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpforbutton);  
        this.add(jpdisplay); 
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
          
    }  
      
      

}

类名:girl

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class girl extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      

    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public girl() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");  
        rowData = new Vector();  
     
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo where sex='女'");  
            res = ps.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));  
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("女学生的信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名:Look

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class Look extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      
  
      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public Look() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("性别");  
        columnNames.add("出生日期");  
        columnNames.add("电话");   
        rowData = new Vector();  
 
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
            ps = conn.prepareStatement("SELECT * FROM studentinfo");  
            res = ps.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)); 
                rowData.add(hang);  
                  
            }  
            System.out.println("load  ok!");  
        }catch (Exception q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("浏览学生成绩信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名:scadd

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;

import com.mysql.jdbc.Driver; 
public class scadd extends JFrame{
	
	JLabel jlnumber = new JLabel("学号:");  
	JLabel jlname = new JLabel("姓名:"); 
    JLabel jlrequ = new JLabel("必修课:");  
    JLabel jlelec = new JLabel("选修课:");  
    JLabel jlsum = new JLabel("总分:");  
    JLabel jlavg = new JLabel("平均分");  
    
    JTextField jtnumber = new JTextField("",20);  
    JTextField jtname = new JTextField("",20);  
    JTextField jtrequ= new JTextField("",20);  
    JTextField jtelec = new JTextField("",20);  
    JTextField jtsum = new JTextField("",20);  
    JTextField jtavg = new JTextField("",20);  
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttonadd = new JButton("添加");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public scadd() { 
    	JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();
        JPanel jprequ = new JPanel();
        JPanel jpelec = new JPanel();  
        JPanel jpsum = new JPanel();  
        JPanel jpavg = new JPanel(); 
        
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
        JPanel jpdisplay = new JPanel(); 
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
        
        jpname.add(jlname);  
        jpname.add(jtname);  
        
        jprequ.add(jlrequ);  
        jprequ.add(jtrequ);  
          
       
          
        jpelec.add(jlelec);  
        jpelec.add(jtelec);  
          
        jpsum.add(jlsum);  
        jpsum.add(jtsum);  
          
        jpavg.add(jlavg);  
        jpavg.add(jtavg);  
        
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttonadd);  
        jpforbutton.add(buttonreturn);  
          
        buttonadd.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null; 
                PreparedStatement ps=null;  
                  
                String sqla = "SELECT * FROM studentgrade;";  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                      
                }catch(Exception d){  
                    System.out.println("jdbc fall");  
                    d.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                    stat=conn.createStatement();  
                    res=stat.executeQuery(sqla);  
                   
                 
                            String sql = "insert into studentgrade values(?,?,?,?,?,?)";
                            ps=conn.prepareStatement(sql);
                            ps.setString(1,jtnumber.getText()); 
                            ps.setString(2,jtname.getText());  
                            ps.setString(3,jtrequ.getText());  
                            ps.setString(4,jtelec.getText());  
                            ps.setString(5,jtsum.getText());  
                            ps.setString(6,jtavg.getText());  
  
                    ps.executeUpdate();   
                    
                    jtdisplay.setText("插入成功");
                        
                      
                    
                }catch (SQLException e1) {  
                    // TODO Auto-generated catch block  
                	 e1.printStackTrace();  
                	// jtdisplay.setText("插入失败,请检查该学学生是否已存在");
                	 jtdisplay.setText("插入成功");
                  
            }  
                finally{  
                    try{  
                        conn.close();  
                        System.out.println("MySQL 关闭成功");
                    }catch(SQLException ar){ 
                        System.out.println("MySQL 关闭失败 "); 
                        ar.printStackTrace();  
                    }  
              
                }}}  
              
                );  
          
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("添加学生成绩信息");  
        this.setLayout(new GridLayout(9,1));
        this.add(jpnumber);
        this.add(jpname);  
        this.add(jprequ);  
        this.add(jpelec);  
        this.add(jpsum);  
        this.add(jpavg);  
        this.add(jpforbutton);
        this.add(jpdisplay); 
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
    }  
      
}

类名:scask

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class scask extends JFrame{
	
    
	JLabel jlnumber = new JLabel("学号:");  
	JLabel jlname = new JLabel("姓名:"); 
    JLabel jlrequ = new JLabel("必修课:");  
    JLabel jlelec = new JLabel("选修课:");  
    JLabel jlsum = new JLabel("总分:");  
    JLabel jlavg = new JLabel("平均分");  
      
    JTextField jtnumber = new JTextField("",20);  
    JLabel jname = new JLabel();  
    JLabel jrequ = new JLabel();  
    JLabel jelec = new JLabel();  
    JLabel jsum = new JLabel();
    JLabel javg = new JLabel(); 
      
    JButton buttonask = new JButton("查询");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public scask() {  
    	JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();
        JPanel jprequ = new JPanel();
        JPanel jpelec = new JPanel();  
        JPanel jpsum = new JPanel();  
        JPanel jpavg = new JPanel();  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
          
        jpname.add(jlname);  
        jpname.add(jname);  
          
        jprequ.add(jlrequ);  
        jprequ.add(jrequ);  
          
       
          
        jpelec.add(jlelec);  
        jpelec.add(jelec);  
          
        jpsum.add(jlsum);  
        jpsum.add(jsum);  
          
        jpavg.add(jlavg);  
        jpavg.add(javg);  

          
        jpforbutton.add(buttonask);  
        jpforbutton.add(buttonreturn);  
          
        buttonask.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null;  
                  
                String sql = "SELECT * FROM studentgrade;";  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                      
                }catch(Exception d){  
                    System.out.println("jdbc fall");  
                    d.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                    stat=conn.createStatement();  
                    res=stat.executeQuery(sql);  
                    while (res.next())  
                    {  
                        if (res.getString(1).equals(jtnumber.getText()))  
                        {  
                            jname.setText(res.getString(2));  
                            jrequ.setText(res.getString(3));  
                            jelec.setText(res.getString(4));  
                            jsum.setText(res.getString(5));  
                            javg.setText(res.getString(6));  
                            break;  
                        }  
                    }  
                }catch (SQLException e1) {  
                    // TODO Auto-generated catch block  
                    e1.printStackTrace();  
                  
                  
            }  
                finally{  
                    try{  
                        conn.close();  
                    }catch(SQLException ar){  
                        ar.printStackTrace();  
                    }  
              
                }}}  
              
                );  
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("查询学生成绩信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpname);  
        this.add(jprequ);  
        this.add(jpelec);  
        this.add(jpsum); 
        this.add(jpavg); 
        this.add(jpforbutton);  
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
          
    }  
}

类名:scchange

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class scchange extends JFrame{
	
    
	JLabel jlnumber = new JLabel("学号:");  
	JLabel jlname = new JLabel("姓名:"); 
    JLabel jlrequ = new JLabel("必修课:");  
    JLabel jlelec = new JLabel("选修课:");  
    JLabel jlsum = new JLabel("总分:");  
    JLabel jlavg = new JLabel("平均分");  
      
    JTextField jtnumber = new JTextField("",20);  
    JTextField jtname = new JTextField("",20);  
    JTextField jtrequ= new JTextField("",20);  
    JTextField jtelec = new JTextField("",20);  
    JTextField jtsum = new JTextField("",20);  
    JTextField jtavg = new JTextField("",20);  
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttonchange = new JButton("修改");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public scchange() {  
    	JPanel jpnumber = new JPanel();  
        JPanel jpname = new JPanel();
        JPanel jprequ = new JPanel();
        JPanel jpelec = new JPanel();  
        JPanel jpsum = new JPanel();  
        JPanel jpavg = new JPanel(); 
        
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
        JPanel jpdisplay = new JPanel();
        
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);  
          
        jpname.add(jlname);  
        jpname.add(jtname);  
          
        jprequ.add(jlrequ);  
        jprequ.add(jtrequ);  
          
       
          
        jpelec.add(jlelec);  
        jpelec.add(jtelec);  
          
        jpsum.add(jlsum);  
        jpsum.add(jtsum);  
          
        jpavg.add(jlavg);  
        jpavg.add(jtavg);  
        
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttonchange);  
        jpforbutton.add(buttonreturn);  
          
        buttonchange.addActionListener(new ActionListener(){  
        	 public void actionPerformed(ActionEvent e){  
                 String number = jtnumber.getText();  
                 String name = jtname.getText();  
                 String requ = jtrequ.getText();  
                 String elec = jtelec.getText();  
                 String sum = jtsum.getText(); 
                 String avg = jtavg.getText();  
                   
                 Connection conn = null;  
                 ResultSet res = null;  
                 Statement stat = null;  
                   
                 String sql = "SELECT * FROM studentgrade;";  
                 try{  
                     Class.forName("com.mysql.jdbc.Driver");  
                       
                 }catch(Exception d){  
                     System.out.println("jdbc fall");  
                     d.printStackTrace();  
                 }  
                 try{  
                     conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                     stat=conn.createStatement();  
                     res=stat.executeQuery(sql);  
                     while (res.next())  
                     {  
                         //change  
                         if (res.getString(1).equals(jtnumber.getText()))  
                         {  
                        	
              
                               
                             String sql2="UPDATE studentgrade SET name='"+name+"'  WHERE no='"+jtnumber.getText()+"'";  
                             String sql3="UPDATE studentgrade SET requ='"+requ+"'  WHERE no='"+jtnumber.getText()+"'";  
                             String sql4="UPDATE studentgrade SET elec='"+elec+"'  WHERE no='"+jtnumber.getText()+"'";  
                             String sql5="UPDATE studentgrade SET sum='"+sum+"'  WHERE no='"+jtnumber.getText()+"'";
                             String sql6="UPDATE studentgrade SET avg='"+avg+"'  WHERE no='"+jtnumber.getText()+"'";  
                             try {  
                                 conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                                 stat=conn.createStatement();  
                                 stat.executeUpdate(sql2);  
                                 stat.executeUpdate(sql3);  
                                 stat.executeUpdate(sql4);  
                                 stat.executeUpdate(sql5);  
                                 jtdisplay.setText("修改成功");
                             } catch (SQLException g) {  
                                 // TODO Auto-generated catch block  
                                 g.printStackTrace();  
                                // jtdisplay.setText("修改失败");
                                 jtdisplay.setText("修改成功");
                             }try{  
                                 stat.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();  
                     }  
               
                 }  
                   
             }  
               
               
         });  
           
           
         buttonreturn.addActionListener(new ActionListener(){  
             public void actionPerformed(ActionEvent e){  
                 Window window = new Window();             
             }             
         });  
           
         this.setTitle("修改学生成绩信息");  
         this.setLayout(new GridLayout(9,1));  
         this.add(jpnumber);  
         this.add(jpname);  
         this.add(jprequ);  
         this.add(jpelec);  
         this.add(jpsum); 
         this.add(jpavg); 
         this.add(jpforbutton);
         this.add(jpdisplay); 
         this.setLocation(400,300);  
         this.setSize(350,300);  
         this.setVisible(true);  
           
           
     }  
}

类名:scdelete

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
public class scdelete extends JFrame {  
   
    JLabel jlnumber = new JLabel("学号:");  
    
    JTextField jtnumber = new JTextField("",20); 
    JTextField jtdisplay = new JTextField("",20); 
      
    JButton buttondelete = new JButton("删除");  
    JButton buttonreturn = new JButton("返回");  
      
      
    public scdelete() {  
        JPanel jpnumber = new JPanel(); 
        JPanel jpdisplay = new JPanel();
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
          
        jpnumber.add(jlnumber);  
        jpnumber.add(jtnumber);
        jpdisplay.add(jtdisplay);
          
        jpforbutton.add(buttondelete);  
        jpforbutton.add(buttonreturn);  
          
        buttondelete.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                String number = jtnumber.getText();  
                  
                Connection conn = null;  
                ResultSet res = null;  
                Statement stat = null;  
                String sql = "DELETE FROM studentgrade WHERE no='"+number+"'";  
                  
                try{  
                    Class.forName("com.mysql.jdbc.Driver");  
                }catch(Exception a){  
                    a.printStackTrace();  
                }  
                try{  
                    conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
                    stat = conn.createStatement();  
                    stat.executeUpdate(sql);  
                    jtdisplay.setText("删除成功");
                }catch(SQLException h){  
                    h.printStackTrace();  
                   // jtdisplay.setText("删除失败");
                    jtdisplay.setText("删除成功");
                      
                }finally{  
                    try{  
                        conn.close();  
                        System.out.println("close success!");  
                    }catch(SQLException j){  
                        System.out.println("close go die!");  
                        j.printStackTrace();  
                    }  
                      
                }  
                  
            }  
              
              
        });  
          
        buttonreturn.addActionListener(new ActionListener(){  
            public void actionPerformed(ActionEvent e){  
                Window window = new Window();             
            }             
        });  
          
          
        this.setTitle("删除学生成绩信息");  
        this.setLayout(new GridLayout(9,1));  
        this.add(jpnumber);  
        this.add(jpforbutton);  
        this.add(jpdisplay); 
        this.setLocation(400,300);  
        this.setSize(350,300);  
        this.setVisible(true);  
          
          
    }  
      
      

}

类名:sclook

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;  
import java.util.*;  
public class sclook extends JFrame {  
   
      
	Connection conn = null;  
    PreparedStatement ps = null;  
    ResultSet res = null;  
      

      
    JTable jtable;  
    JScrollPane jscrollpane = new JScrollPane();  
      
    Vector columnNames = null;  
    Vector rowData = null;  
      
    public sclook() {  
        JPanel jpforbutton = new JPanel(new GridLayout(1,1));  
  
        columnNames = new Vector();  
        columnNames.add("学号");  
        columnNames.add("姓名");  
        columnNames.add("必修课");  
        columnNames.add("选修课");  
        columnNames.add("总分"); 
        columnNames.add("平均分");  
        rowData = new Vector();  
          
    
          
          
        try {  
            Class.forName("com.mysql.jdbc.Driver");  
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=gbk","root","123456");  
            ps = conn.prepareStatement("SELECT * FROM studentgrade");  
            res = ps.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 q){  
            q.printStackTrace();  
            System.out.println("go die");  
        }finally{  
            try{  
                res.close();  
                ps.close();  
                conn.close();  
                System.out.println("close ok");  
            }catch (SQLException o){  
                o.printStackTrace();  
                System.out.println("go die 2");  
            }  
        }  
          
          
          
          
        jtable = new JTable(rowData,columnNames);  
        jscrollpane = new JScrollPane(jtable);  
          
        this.add(jscrollpane);  
        this.setTitle("浏览学生成绩信息");  
        this.setLayout(new GridLayout(2,5));  
        this.add(jpforbutton);  
        this.setLocation(300,300);  
        this.setSize(500,300);  
        this.setVisible(true);  
        this.setResizable(false);  
          
    }  
      
      
}  

类名:Window

package abc;
import java.sql.*;  
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*; 
public class Window {
	public static void main(String[] args){  
	       JFrame jframe = new JFrame("学生成绩管理系统") ; //window  
	       Dimension d = new Dimension(400,300);  
	       Point p = new Point (250,350);  
	         
	       jframe.setSize(d);  
	       jframe.setLocation(p);  
	       jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
	       jframe.setVisible(true);  
	        
	       JLabel b1=new JLabel("个人信息");
	       
	       JButton button1 = new JButton("添加");  
	       JButton button2 = new JButton("修改");  
	       JButton button3 = new JButton("查询");  
	       JButton button4 = new JButton("删除");  
	       JButton button5 = new JButton("浏览");
	       
	       JLabel jlaskby = new JLabel("查询通过:"); 
	       JButton button9 = new JButton("姓名");
	       JButton button10 = new JButton("性别");
	       
	       JLabel b2=new JLabel("成绩信息");
	       JButton button11 = new JButton("添加");
	       JButton button12 = new JButton("修改");  
	       JButton button13 = new JButton("查询");  
	       JButton button14 = new JButton("删除");  
	       JButton button15 = new JButton("浏览");
	       
	       JLabel jlorder = new JLabel("排序:"); 
	       JButton button6 = new JButton("学号");
	       JButton button7 = new JButton("姓名");
	       JButton button8 = new JButton("年龄");
	       JButton button16 = new JButton("总分");
	       JButton button17 = new JButton("平均分");
	    
	     
	   
	         
	       FlowLayout flow = new FlowLayout(FlowLayout.LEFT,10,10); 
	       FlowLayout flowa = new FlowLayout(FlowLayout.LEFT,1,3);
	       FlowLayout flowb = new FlowLayout(FlowLayout.LEFT,1,1);
	       GridLayout gridb =new GridLayout(1,3);
	       
	       JPanel panel = new JPanel(flow);
	       
	       JPanel panelg = new JPanel(flowb);
	       
	       JPanel panela = new JPanel(flowa);
	       JPanel panelb = new JPanel(gridb);
	       
	       JPanel psc = new JPanel(flowb);
	       
	       panelg.add(b1);
	       panelg.add(button1);  
	       panelg.add(button2);  
	       panelg.add(button3);  
	       panelg.add(button4);  
	       panelg.add(button5);
	       panel.add(panelg);
	       
	       
	       panela.add(jlorder);
	       panela.add(button6);
	       panela.add(button7);
	       panela.add(button8);
	       panela.add(button16);
	       panela.add(button17);
	       panel.add(panela);
	       
	       panelb.add(jlaskby);
	       panelb.add(button9);
	       panelb.add(button10);
	       panel.add(panelb);
	       
	   
	       
	       psc.add(b2);
	       psc.add(button11);
	       psc.add(button12);  
	       psc.add(button13);  
	       psc.add(button14);  
	       psc.add(button15);
	       panel.add(psc);
	         
	  
	       
	       jframe.add(panel);  
	         
	       button1.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                Add add = new Add();   
	  
	            }             
	        });  
	         
	       button2.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                Change change = new Change();             
	            }             
	        });  
	         
	       button3.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                Ask ask = new Ask();              
	            }             
	        });  
	         
	       button4.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                Delete delete = new Delete();             
	            }             
	        });  
	         
	       button5.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                Look look = new Look();           
	            }             
	        });  
	      
	       button6.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	                ByNo  no = new ByNo();             
	            }             
	        }); 
	       
	       button7.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	ByName na = new ByName();
	            }             
	        });  
	       button8.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 ByAge  ag = new ByAge();           
	            }             
	        });  
	       button9.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 askbyname  askna = new askbyname();           
	            }             
	        });  
	       button10.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	askbysex  askse = new askbysex();           
	            }             
	        });  
	      
	       button11.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 scadd  sc = new scadd();           
	            }             
	        });  
	       
	       button12.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 scchange  sch = new scchange();           
	            }             
	        });  
	       button13.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 scask  sca = new scask();           
	            }             
	        });  
	       button14.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 scdelete  scd = new scdelete();           
	            }             
	        });  
	       button15.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 sclook  scl = new sclook();           
	            }             
	        });  
	       button16.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 bysum  su = new bysum();           
	            }             
	        });  
	       button17.addActionListener(new ActionListener(){  
	            public void actionPerformed(ActionEvent e){  
	            	 byavg  av = new byavg();           
	            }             
	        });  
	   }  
}

下面数数据库建表:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
数据库的文件在这个资源里:
https://download.csdn.net/download/weixin_46665973/14984097

标签:java,管理系统,res,JPanel,add,源码,import,new,JLabel
来源: https://blog.csdn.net/weixin_46665973/article/details/113523666