服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|易语言|

服务器之家 - 编程语言 - JAVA教程 - Java基于MySQL实现学生管理系统

Java基于MySQL实现学生管理系统

2021-03-19 10:54Hyouka1203 JAVA教程

这篇文章主要为大家详细介绍了Java基于MySQL实现学生管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文为大家分享了java基于mysql实现学生管理系统,供大家参考,具体内容如下

因为实验室要交作业然后就做了一个学生管理系统,贴个代码纪念一下,做的太急界面什么的也比较差。

还有一些小细节没有完善不过还是能实现主要的功能的。

Java基于MySQL实现学生管理系统

window是主界面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package first;
 
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);
  
 jbutton button1 = new jbutton("添加");
 jbutton button2 = new jbutton("修改");
 jbutton button3 = new jbutton("查询");
 jbutton button4 = new jbutton("删除");
 jbutton button5 = new jbutton("浏览");
  
 flowlayout flow = new flowlayout(flowlayout.left,10,10);
 jpanel panel = new jpanel(flow);
 panel.add(button1);
 panel.add(button2);
 panel.add(button3);
 panel.add(button4);
 panel.add(button5);
  
 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(); 
  
 });
  
 }
 
}

add是添加

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package first;
 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
import com.mysql.jdbc.driver;
 
import first.window;
 
public class add extends jframe {
 private static final long serialversionuid = -1928970409928880648l;
 
 jlabel jlnumber = new jlabel("学号:");
 jlabel jlname = new jlabel("姓名:");
 jlabel jlsex = new jlabel("性别:");
 jlabel jlbirthday = new jlabel("出生日期:");
 jlabel jldepartment = new jlabel("学院:");
 
 jtextfield jtnumber = new jtextfield("",20);
 jtextfield jtname = new jtextfield("",20);
 jtextfield jtsex = new jtextfield("",20);
 jtextfield jtbirthday = new jtextfield("",20);
 jtextfield jtdepartment = 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 jpdepartment = 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);
  
 jpdepartment.add(jldepartment);
 jpdepartment.add(jtdepartment);
  
 jpforbutton.add(buttonadd);
 jpforbutton.add(buttonreturn);
  
 buttonadd.addactionlistener(new actionlistener(){
  public void actionperformed(actionevent e){
   
  //add
  connection conn = null;
  statement stat = null;
  preparedstatement ps=null;
  string sql = "insert into student(number,name,sex,birthday,department) "
   + "values(?,?,?,?,?)";
  try{
   class.forname("driver");
   system.out.println("jbdc 加载成功!");
  }catch(exception a){
   system.out.println("jbdc 狗带!");
   a.printstacktrace();
  }
  try{
   conn=drivermanager.getconnection("jdbc:mysql://localhost:3306/javastu","root","123");
   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,jtdepartment.gettext());
 
   ps.executeupdate();
   
   //system.out.println("mysql 连接成功!");
   //stat = conn.createstatement();
   //stat.executeupdate(sql);
   //system.out.println("插入数据成功!");
   
  }catch (sqlexception b){
   b.printstacktrace();
  }finally{
   try{
   conn.close();
   system.out.println("mysql 关闭成功");
   }catch (sqlexception c){
   system.out.println("mysql 关闭失败 ");
   c.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(jpdepartment);
 this.add(jpforbutton);
 this.setlocation(400,300);
 this.setsize(350,300);
 this.setvisible(true);
  
 }
 
 
}

ask是查询

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package first;
 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
import first.window;
 
public class ask extends jframe {
 private static final long serialversionuid = -1928970409928880648l;
 
 jlabel jlnumber = new jlabel("学号:");
 jlabel jlname = new jlabel("姓名:");
 jlabel jlsex = new jlabel("性别:");
 jlabel jlbirthday = new jlabel("出生日期:");
 jlabel jldepartment = new jlabel("学院:");
 
 jtextfield jtnumber = new jtextfield("",20);
 jlabel jname = new jlabel();
 jlabel jsex = new jlabel();
 jlabel jbirthday = new jlabel();
 jlabel jdepartment = 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 jpdepartment = 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);
  
 jpdepartment.add(jldepartment);
 jpdepartment.add(jdepartment);
  
 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 number,name,sex,birthday,department from student;";
  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/javastu","root","123");
   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));
    jdepartment.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(jpdepartment);
 this.add(jpforbutton);
 this.setlocation(400,300);
 this.setsize(350,300);
 this.setvisible(true);  
 
}

change是修改

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package first;
 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
 
import first.window;
 
public class change extends jframe {
 private static final long serialversionuid = -1928970409928880648l;
 
 jlabel jlnumber = new jlabel("学号:");
 jlabel jlname = new jlabel("姓名:");
 jlabel jlsex = new jlabel("性别:");
 jlabel jlbirthday = new jlabel("出生日期:");
 jlabel jldepartment = new jlabel("学院:");
 
 jtextfield jtnumber = new jtextfield("",20);
 jtextfield jtname = new jtextfield("",20);
 jtextfield jtsex = new jtextfield("",20);
 jtextfield jtbirthday = new jtextfield("",20);
 jtextfield jtdepartment = 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 jpdepartment = 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);
  
 jpdepartment.add(jldepartment);
 jpdepartment.add(jtdepartment);
  
 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 department = jtdepartment.gettext();
   
  connection conn = null;
  resultset res = null;
  statement stat = null;
   
  string sql = "select number,name,sex,birthday,department from student;";
  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/javastu","root","123");
   stat=conn.createstatement();
   res=stat.executequery(sql);
   while (res.next())
   {
   //change
   if (res.getstring(1).equals(jtnumber.gettext()))
   {
   try{
    class.forname("com.mysql.jdbc.driver");
   }catch(exception d){
    system.out.println("jdbc fall");
    d.printstacktrace();
   }
    
    string sql2="update student set name='"+name+"' where number='"+jtnumber.gettext()+"'";
    string sql3="update student set sex='"+sex+"' where number='"+jtnumber.gettext()+"'";
    string sql4="update student set birthday='"+birthday+"' where number='"+jtnumber.gettext()+"'";
    string sql5="update student set department='"+department+"' where number='"+jtnumber.gettext()+"'";
    try {
    conn=drivermanager.getconnection("jdbc:mysql://localhost:3306/javastu","root","123");
    stat=conn.createstatement();
    stat.executeupdate(sql2);
    stat.executeupdate(sql3);
    stat.executeupdate(sql4);
    stat.executeupdate(sql5);
    } catch (sqlexception g) {
    // todo auto-generated catch block
    g.printstacktrace();
    }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(jpdepartment);
 this.add(jpforbutton);
 this.setlocation(400,300);
 this.setsize(350,300);
 this.setvisible(true);  
 
}

delete是删除

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package first;
 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
 import javax.swing.*;
 
import first.window;
 
 
 
 public class delete extends jframe {
 private static final long serialversionuid = -1928970409928880648l;
   
 jlabel jlnumber = new jlabel("学号:");
  
 jtextfield jtnumber = new jtextfield("",20);
  
 jbutton buttondelete = new jbutton("删除");
 jbutton buttonreturn = new jbutton("返回");
  
  
 public delete() {
  jpanel jpnumber = new jpanel();
  jpanel jpforbutton = new jpanel(new gridlayout(1,1));
  
  jpnumber.add(jlnumber);
  jpnumber.add(jtnumber);
  
  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 student where number='"+number+"'";
   
   try{
   class.forname("com.mysql.jdbc.driver");
   }catch(exception a){
   a.printstacktrace();
   }
   try{
   conn=drivermanager.getconnection("jdbc:mysql://localhost:3306/javastu","root","123");
   stat = conn.createstatement();
   stat.executeupdate(sql);
   }catch(sqlexception h){
   h.printstacktrace();
    
   }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.setlocation(400,300);
  this.setsize(350,300);
  this.setvisible(true);
  
 }
  
 }

 look是浏览

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package first;
 
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
 
import first.window;
 
public class look extends jframe {
 private static final long serialversionuid = -1928970409928880648l;
 
 connection conn = null;
 preparedstatement ps = null;
 resultset res = null;
 
 
 //jbutton buttonlook = new jbutton("浏览");
 //jbutton buttonreturn = new jbutton("返回");
 
 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();
  
 //jpforbutton.add(buttonlook);
 //jpforbutton.add(buttonreturn);
  
  
 try {
  class.forname("com.mysql.jdbc.driver");
  conn = drivermanager.getconnection("jdbc:mysql://localhost:3306/javastu","root","123");
  ps = conn.preparestatement("select * from student");
  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);
  
 }
 
 
}

一些运行的界面:

Java基于MySQL实现学生管理系统

Java基于MySQL实现学生管理系统

Java基于MySQL实现学生管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:http://blog.csdn.net/qq_34472846/article/details/51097965

延伸 · 阅读

精彩推荐
  • JAVA教程java实现监听u盘示例分享

    java实现监听u盘示例分享

    这篇文章主要介绍了java实现监听u盘示例,需要的朋友可以参考下 ...

    java技术网2182019-11-14
  • JAVA教程Java简单高效实现分页功能

    Java简单高效实现分页功能

    这篇文章主要介绍了Java简单高效实现分页功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...

    程序零世界7782020-08-30
  • JAVA教程Java学习笔记之观察者模式

    Java学习笔记之观察者模式

    这篇文章主要为大家详细介绍了Java学习笔记之观察者模式的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    神仙果5162021-02-06
  • JAVA教程Java垃圾回收finalize()作用详解

    Java垃圾回收finalize()作用详解

    Java 技术允许使用 finalize() 方法在垃圾收集器将对象从内存中清除出去之前做必要的清理工作,这个方法是由垃圾收集器在确定这个对象没有被引用时对这...

    lijiao2702020-01-07
  • JAVA教程Java基础教程之对象引用

    Java基础教程之对象引用

    这篇文章主要介绍了Java基础教程之对象引用,“对象引用”(object reference)是一个重要重要概念,涉及内存,需要的朋友可以参考下 ...

    junjie1972019-11-27
  • JAVA教程java中BigDecimal的操作方法

    java中BigDecimal的操作方法

    这篇文章主要介绍了java中BigDecimal的操作方法,较为详细的分析了BigDecimal类在进行商业计算时的应用方法,精度以及注意事项等问题,需要的朋友可以参考下...

    shichen20143352019-12-07
  • JAVA教程Java+mysql本地图片上传数据库及下载示例

    Java+mysql本地图片上传数据库及下载示例

    本篇文章主要介绍了Java+mysql本地图片上传数据库及下载示例,具有一定的参加价值,有兴趣的可以了解一下。...

    Ro_kin5102020-07-31
  • JAVA教程SpringMVC源码解析之消息转换器HttpMessageConverter

    SpringMVC源码解析之消息转换器HttpMessageConverter

    本篇文章主要介绍了SpringMVC源码解析之消息转换器HttpMessageConverter ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    相见欢4332021-02-24