java等级_Java分级考试

石家庄铁道大学选课管理系统

1、项目需求:

本项目所开发的学生选课系统完成学校对学生的选课信息的统计与管理,减少数据漏掉的情况,同时也节约人力、物力和财力。告别以往的人工统计。

2.系统要求与功能设计

2.1 页面要求

(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;

(2)网站页面整体风格统一;

(3)首页(登录页)要求实现不同用户登录后,进入的功能页不相同。

(4)教师功能页:有添加课程、修改个人信息、浏览选课学生信息三个模块。

(5)学生功能页:有修改个人信息、浏览课程信息、选课三个功能模块。

(5)管理员功能页:有添加教师信息、添加学生信息两个模块。

2.2功能要求:

(1)添加教师信息:管理员可以添加教师基本信息,教师基本信息包括:教师工号(八位数字组成,例如02000081)、教师姓名、教师性别、教师所在学院、职称(教授、副教授、讲师、助教)组成;

(2)添加学生信息:管理可以添加学生基本信息,学生基本信息包括学号(八位数字组成,例如20180052)、学生姓名、学生性别、所在班级、所属专业组成;

(3)添加课程信息:教师登陆后,可以添加自己任职的课程基本信息,课程基本信息包括:课程编号(六位数字组成,例如050013),课程名称、选课人数、任课教师(任课教师不需录入,那位教师填写课程信息,那位教师就是任课教师);

(4)修改个人信息:教师或学生登陆后可以修改个人信息,但教师工号或学号不能修改,另外教师或学生只能修改自己的信息,无法看到或修改其他学生或教师的基本信息。

(5)浏览课程信息:学生登陆后可以看到所有课程的列表信息,点击课程名称可以查看课程的详细信息,包括已选课人数;点击教师名称可以查看教师的详细信息。

(6)选课:进入选课页面,课程信息列表显示所有选课人数未达到课程设置的选课人数上限,点击课程名称可以看到课程详细信息,点击课程详细信息页面的“选课”按钮,可以实现选课功能。

(7)浏览选课学生信息:教师进入该页面后,可以看到自己设置的课程信息列表,点击课程名称,可以看到,选择该课程的所有学生基本信息列表。

(8)登陆功能:管理员、教师、学生登陆后可以看到不同的功能页面,教师或学生登陆后只能看到自己的相关信息,不同教师、不同学生登陆后无法查看其他人的信息。(要求至少创建两个教师用户、十个学生用户演示选课过程)

3数据库设计:

要求实现课程基本信息表、教师基本信息表、学生基本信息表、选课基本信息表。(提示:选课基本信息包括课程编号、教师编号、学号等基本信息)

4、WEB发布:

要求可以实现在浏览器直接访问系统。

本系统只完成了一部分功能,其他功能还需要进一步的学习

下面是连接数据库的代码

packageccc;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;public classS {public staticConnection getConnection() {try{//1 加载驱动

Class.forName("com.mysql.cj.jdbc.Driver");

}catch(ClassNotFoundException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

String user= "root";

String password= "123456";

String url= "jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";

Connection connection= null;try{//2 创建链接对象connection

connection =DriverManager.getConnection(url, user, password);

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}returnconnection;

}//关闭资源的方法

public static voidclose(Connection connection) {try{if (connection != null) {

connection.close();

}

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}public static voidclose(PreparedStatement preparedStatement) {try{if (preparedStatement != null) {

preparedStatement.close();

}

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}public static voidclose(ResultSet resultSet) {try{if (resultSet != null) {

resultSet.close();

}

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}

}

}

下面是数据库表

ca91b4685149f50e386b2093696b6a28.png

下面是具体的代码

Welcome!

欢迎来到选课系统

我是管理员

我是学生

我是教师

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

修改界面

17

18

19

20 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

21 String num = request.getParameter("num");22 String name = request.getParameter("name");23 String sex = request.getParameter("sex");24 String zhi = request.getParameter("zhi");25 String collage = request.getParameter("collage");26 Connection conn = null; //定义静态数据库连接

27 Statement stat = null;28 conn =S.getConnection();29 stat =conn.createStatement();30 stat.execute("update a set num='" + num + "' ,name='" + name + "' ,sex='" + sex + "' ,zhi='" + zhi+"' where name='" + name + "'");31 ResultSet rs = stat.executeQuery("select * from a where name='" + name + "'"); //查找data表id字段

32 %>

33

34

修改成功!

35

36

修改前后的信息对比:

37


38

39

40

41

42

工号

43

姓名

44

性别

45

学院

46

职称

47

48

49 while(rs.next())50 {51 out.print("

");52 out.print("" + rs.getString("num") + ""); //输出name内容

53 out.print("

" + rs.getString("name") + ""); //输出gender内容

54 out.print("

" + rs.getString("sex") + "");55 out.print("" + rs.getString("collage") + ""); //输出major内容

56 out.print("

" + rs.getString("zhi") + "");57 out.print("");58 }59 %>

60

61

62

63 返回主页面

64

65 if(rs != null)66 {67 rs.close(); //关闭结果集,但是rs还是有null值。

68 rs = null; //将rs滞空。

69 }70 if(stat != null)71 {72 stat.close(); //关闭stat。

73 stat = null; //滞空stat。

74 }75 if(conn != null)76 {77 conn.close(); //关闭数据库连接

78 conn = null;79 }80 %>

81

82

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

修改界面

17

18

19

20 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

21 String num = request.getParameter("num");22 String name = request.getParameter("name");23 String sex = request.getParameter("sex");24 String cla = request.getParameter("cla");25 String collage = request.getParameter("collage");26 Connection conn = null; //定义静态数据库连接

27 Statement stat = null;28 conn =S.getConnection();29 stat =conn.createStatement();30 stat.execute("update b set num='" + num + "' ,name='" + name + "' ,sex='" + sex + "' ,cla='" + cla+"' where name='" + name + "'");31 ResultSet rs = stat.executeQuery("select * from b where name='" + name + "'"); //查找data表id字段

32 %>

33

34

修改成功!

35

36

修改前后的信息对比:

37


38

39

40

41

42

学号

43

姓名

44

性别

45

班级

46

学院

47

48

49 while(rs.next())50 {51 out.print("

");52 out.print("" + rs.getString("num") + ""); //输出name内容

53 out.print("

" + rs.getString("name") + ""); //输出gender内容

54 out.print("

" + rs.getString("sex") + "");55 out.print("" + rs.getString("cla") + ""); //输出major内容

56 out.print("

" + rs.getString("collage") + "");57 out.print("");58 }59 %>

60

61

62

63 返回

64

65 if(rs != null)66 {67 rs.close(); //关闭结果集,但是rs还是有null值。

68 rs = null; //将rs滞空。

69 }70 if(stat != null)71 {72 stat.close(); //关闭stat。

73 stat = null; //滞空stat。

74 }75 if(conn != null)76 {77 conn.close(); //关闭数据库连接

78 conn = null;79 }80 %>

81

82

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

志愿者信息

16

17

18

19

20 String num = request.getParameter("num");21 String name = request.getParameter("name");22 String shu = request.getParameter("shu");23 String ming = request.getParameter("ming");24 Connection conn = null; //定义静态数据库连接

25 Statement stat = null;26 ResultSet rs = null; //将rs滞空。

27 conn =S.getConnection();28 stat =conn.createStatement();29 rs = stat.executeQuery("select * from c"); //查找data表

30 %>

31

32

课程信息

33


34

35

全部信息如下

36

37

38

课程编号

39

课程名称

40

选课人数

41

任课教师

42

43

44

45 while(rs.next())46 {47 out.print("

");48 out.print("" + rs.getString("num") + "");49 out.print("" + rs.getString("name") + ""); //输出name内容

50 out.print("

" + rs.getString("shu") + ""); //输出gender内容

51 out.print("

" + rs.getString("ming") + "");52

53 out.print("

");54 %>

55

56

57 out.print("");58 }59 %>

60

61

62

63

按课程名称查询:64

65

66

67

68

69

70

按教师姓名查询:71

72

73

74

75

76

77 返回主页面

78

79 if(rs != null)80 {81 rs.close(); //关闭结果集,但是rs还是有null值。

82 rs = null; //将rs滞空。

83 }84 if(stat != null)85 {86 stat.close(); //关闭stat。

87 stat = null; //滞空stat。

88 }89 if(conn != null)90 {91 conn.close(); //关闭数据库连接

92 conn = null;93 }94 %>

95

96

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

志愿者信息

16

17

18

19

20 String num = request.getParameter("num");21 String name = request.getParameter("name");22 String sex = request.getParameter("sex");23 String zhi = request.getParameter("zhi");24 String collage = request.getParameter("collage");25 Connection conn = null; //定义静态数据库连接

26 Statement stat = null;27 ResultSet rs = null; //将rs滞空。

28 conn =S.getConnection();29 stat =conn.createStatement();30 rs = stat.executeQuery("select * from a"); //查找data表

31 %>

32

33

信息

34


35

36

全部信息如下

37

38

39

工号

40

姓名

41

性别

42

学院

43

职称

44

45

46

47 while(rs.next())48 {49 out.print("

");50 out.print("" + rs.getString("num") + ""); //输出name内容

51 out.print("

" + rs.getString("name") + ""); //输出gender内容

52 out.print("

" + rs.getString("sex") + "");53 out.print("" + rs.getString("collage") + ""); //输出major内容

54 out.print("

" + rs.getString("zhi") + "");55 out.print("");56 %>

57

58

">修改

59

60 out.print("");61 }62 %>

63

64

65 返回主页面

66

67 if(rs != null)68 {69 rs.close(); //关闭结果集,但是rs还是有null值。

70 rs = null; //将rs滞空。

71 }72 if(stat != null)73 {74 stat.close(); //关闭stat。

75 stat = null; //滞空stat。

76 }77 if(conn != null)78 {79 conn.close(); //关闭数据库连接

80 conn = null;81 }82 %>

83

84

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

志愿者信息

16

17

18

19

20 String num = request.getParameter("xing");21 String name = request.getParameter("name");22

23 Connection conn = null; //定义静态数据库连接

24 Statement stat = null;25 ResultSet rs = null; //将rs滞空。

26 conn =S.getConnection();27 stat =conn.createStatement();28 rs = stat.executeQuery("select * from d"); //查找data表

29 %>

30

31

信息

32


33

34

全部信息如下

35

36

37

38

姓名

39

课程名称

40

41

42

43

44 while(rs.next())45 {46 out.print("

");47 out.print("" + rs.getString("xing") + ""); //输出name内容

48 out.print("

" + rs.getString("name") + ""); //输出gender内容

49

50

51 out.print("

");52 %>

53

54

55 out.print("");56 }57 %>

58

59

60

61

62 返回

63

64 if(rs != null)65 {66 rs.close(); //关闭结果集,但是rs还是有null值。

67 rs = null; //将rs滞空。

68 }69 if(stat != null)70 {71 stat.close(); //关闭stat。

72 stat = null; //滞空stat。

73 }74 if(conn != null)75 {76 conn.close(); //关闭数据库连接

77 conn = null;78 }79 %>

80

81

1

2

3 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

4 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

5 %>

6

7 String path = request.getContextPath(); //相对Path设置

8 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

9 %>

10

11

12

13

青年志愿者信息管理系统

14

15

16 function validate()17 {18 var num = document.forms[0].num.value; //创建变量name

19 var name = document.forms[0].name.value; //创建变量teacher

20 var shu = document.forms[0].shu.value;21 var ming = document.forms[0].ming.value;22 if(num.length!=6){ //判断姓名位数,必填

23 alert("课程编号为六位!");24 return false;25 }26 //else if(money.length <= 0){//判断年龄,必填27 //alert("请输入合法价格!");28 //return false;29 //}30 //else if(id.length <= 0){//判断学号位数,必填31 //alert("编号号不能为空,请输入编号!");32 //return false;33 //}34

35 //else if(time.length <= 0){//专业为必填36 //alert("时间不能为空,请输入菜品时间!");37 //return false;38 //}

39 else{40 return true;41 }42 //document.getElementById("form").submit();

43 }44

45

46

47

48

49

添加信息

50


51

52

53 onSubmit="return validate()">

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

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

课程信息

16

17

18

19

20 String num = request.getParameter("num");21 String name = request.getParameter("name");22 String shu = request.getParameter("shu");23 String ming = request.getParameter("ming");24 Connection conn = null; //定义静态数据库连接

25 Statement stat = null;26 ResultSet rs = null; //将rs滞空。

27 conn =S.getConnection();28 stat =conn.createStatement();29 rs = stat.executeQuery("select * from c"); //查找data表

30 %>

31

32

课程信息

33


34

35

全部信息如下

36

37

38

课程编号

39

课程名称

40

选课人数

41

任课教师

42

43

44

45 while(rs.next())46 {47 out.print("

");48 out.print("" + rs.getString("num") + "");49 out.print("" + rs.getString("name") + ""); //输出name内容

50 out.print("

" + rs.getString("shu") + ""); //输出gender内容

51 out.print("

" + rs.getString("ming") + "");52

53 out.print("

");54 %>

55

56

57 out.print("");58 }59 %>

60

61

62

63

按课程名称查询:64

65

66

67

68

69

70

71 返回主页面

72

73 if(rs != null)74 {75 rs.close(); //关闭结果集,但是rs还是有null值。

76 rs = null; //将rs滞空。

77 }78 if(stat != null)79 {80 stat.close(); //关闭stat。

81 stat = null; //滞空stat。

82 }83 if(conn != null)84 {85 conn.close(); //关闭数据库连接

86 conn = null;87 }88 %>

89

90

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

志愿者信息

16

17

18

19

20 String num = request.getParameter("num");21 String name = request.getParameter("name");22 String sex = request.getParameter("sex");23 String cla = request.getParameter("cla");24 String collage = request.getParameter("collage");25 Connection conn = null; //定义静态数据库连接

26 Statement stat = null;27 ResultSet rs = null; //将rs滞空。

28 conn =S.getConnection();29 stat =conn.createStatement();30 rs = stat.executeQuery("select * from b"); //查找data表

31 %>

32

33

信息

34


35

36

全部信息如下

37

38

39

学号

40

姓名

41

性别

42

班级

43

学院

44

45

46

47 while(rs.next())48 {49 out.print("

");50 out.print("" + rs.getString("num") + ""); //输出name内容

51 out.print("

" + rs.getString("name") + ""); //输出gender内容

52 out.print("

" + rs.getString("sex") + "");53 out.print("" + rs.getString("cla") + ""); //输出major内容

54 out.print("

" + rs.getString("collage") + "");55 out.print("");56 %>

57

58

">修改

59

60 out.print("");61 }62 %>

63

64

65 返回主页面

66

67 if(rs != null)68 {69 rs.close(); //关闭结果集,但是rs还是有null值。

70 rs = null; //将rs滞空。

71 }72 if(stat != null)73 {74 stat.close(); //关闭stat。

75 stat = null; //滞空stat。

76 }77 if(conn != null)78 {79 conn.close(); //关闭数据库连接

80 conn = null;81 }82 %>

83

84

1

2

3 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

4 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

5 %>

6

7 String path = request.getContextPath(); //相对Path设置

8 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

9 %>

10

11

12

13

青年志愿者信息管理系统

14

15

16 function validate()17 {18 var num = document.forms[0].num.value; //创建变量name

19 var name = document.forms[0].name.value; //创建变量teacher

20 var sex = document.forms[0].sex.value;21 var collage = document.forms[0].collage.value; //创建变量address

22 var cla = document.forms[0].cla.value;23 if(num.length!=8){ //判断姓名位数,必填

24 alert("学号为八位!");25 return false;26 }27 //else if(money.length <= 0){//判断年龄,必填28 //alert("请输入合法价格!");29 //return false;30 //}31 //else if(id.length <= 0){//判断学号位数,必填32 //alert("编号号不能为空,请输入编号!");33 //return false;34 //}35

36 //else if(time.length <= 0){//专业为必填37 //alert("时间不能为空,请输入菜品时间!");38 //return false;39 //}

40 else{41 return true;42 }43 //document.getElementById("form").submit();

44 }45

46

47

48

49

50

添加信息

51


52

53

54 onSubmit="return validate()">

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

1

2

3 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

4 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

5 %>

6

7 String path = request.getContextPath(); //相对Path设置

8 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

9 %>

10

11

12

13

14

15

16 function validate()17 {18 var num = document.forms[0].num.value; //创建变量name

19 var name = document.forms[0].name.value; //创建变量teacher

20 var sex = document.forms[0].sex.value;21 var collage = document.forms[0].collage.value; //创建变量address

22 var zhi = document.forms[0].zhi.value;23 if(num.length !=8){ //判断姓名位数,必填

24 alert("工号为八位");25 return false;26 }27 //else if(money.length <= 0){//判断年龄,必填28 //alert("请输入合法价格!");29 //return false;30 //}31 //else if(id.length <= 0){//判断学号位数,必填32 //alert("编号号不能为空,请输入编号!");33 //return false;34 //}35

36 //else if(time.length <= 0){//专业为必填37 //alert("时间不能为空,请输入菜品时间!");38 //return false;39 //}

40 else{41 return true;42 }43 //document.getElementById("form").submit();

44 }45

46

47

48

49

50

添加信息

51


52

53

54 onSubmit="return validate()">

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

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

按姓名条件查询

17

18

19

20 String name = request.getParameter("name");21 Connection conn = null; //定义静态数据库连接

22 Statement stat = null; //滞空stat。

23 ResultSet rs = null; //将rs滞空。

24 conn =S.getConnection();25 stat =conn.createStatement();26 rs = stat.executeQuery("select * from c where name like '%" + name + "%'");//查找data表name字段

27 %>

28

29

符合条件的信息

30


31

32

33

34

课程编号

35

课程名称

36

选课人数

37

任课教师

38

39

40

41 while(rs.next())42 {43 out.print("

");44 out.print("" + rs.getString("num") + ""); //输出name内容

45 out.print("

" + rs.getString("name") + ""); //输出gender内容

46 out.print("

" + rs.getString("shu") + "");47 out.print("" + rs.getString("ming") + ""); //输出major内容

48 %>

49

50

51 out.print("

");52 }53

54 %>

55

56

57 返回

58

59 if(rs != null)60 {61 rs.close(); //关闭结果集,但是rs还是有null值。

62 rs = null; //将rs滞空。

63 }64 if(stat != null) //判断stat是否滞空。

65 {66 stat.close(); //关闭stat。

67 stat = null; //滞空stat。

68 }69 if(conn != null)70 {71 conn.close(); //关闭数据库连接

72 conn = null;73 }74 %>

75

76

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

按姓名条件查询

17

18

19

20 String name = request.getParameter("ming");21 Connection conn = null; //定义静态数据库连接

22 Statement stat = null; //滞空stat。

23 ResultSet rs = null; //将rs滞空。

24 conn =S.getConnection();25 stat =conn.createStatement();26 rs = stat.executeQuery("select * from a where name like '%" + name + "%'");//查找data表name字段

27 %>

28

29

符合条件的信息

30


31

32

33

34

工号

35

姓名

36

性别

37

学院

38

职称

39

40

41

42 while(rs.next())43 {44 out.print("

");45 out.print("" + rs.getString("num") + ""); //输出name内容

46 out.print("

" + rs.getString("name") + ""); //输出gender内容

47 out.print("

" + rs.getString("sex") + "");48 out.print("" + rs.getString("collage") + ""); //输出major内容

49 out.print("

" + rs.getString("zhi") + "");50 %>

51

52

53 out.print("

");54 }55

56 %>

57

58

59 返回

60

61 if(rs != null)62 {63 rs.close(); //关闭结果集,但是rs还是有null值。

64 rs = null; //将rs滞空。

65 }66 if(stat != null) //判断stat是否滞空。

67 {68 stat.close(); //关闭stat。

69 stat = null; //滞空stat。

70 }71 if(conn != null)72 {73 conn.close(); //关闭数据库连接

74 conn = null;75 }76 %>

77

78

1

2 pageEncoding="UTF-8"%>

3

4

5

6

7

Welcome!

8

9

欢迎来到选课系统

10

11

12

13 添加学生信息

14 添加教师信息

15 返回

16

17

18

1

2

3 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

4 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

5 %>

6

7 String path = request.getContextPath(); //相对Path设置

8 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

9 %>

10

11

12

13

14

Insert title here

15

16

17 选课成功!18 返回

19

20

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

17

18

19

20 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

21 String num = request.getParameter("num");22 String name = request.getParameter("name");23 String sex = request.getParameter("sex");24 String collage = request.getParameter("collage");25 String zhi = request.getParameter("zhi");26 Connection conn = null; //定义静态数据库连接

27 Statement stat = null;28 ResultSet rs = null; //将rs滞空。

29 conn =S.getConnection();30 stat =conn.createStatement();31 //String sql = ;//向对应的数据字段添加数据

32 stat.executeUpdate("insert into a(num,name,sex,collage,zhi) values('" +num33 + "','" + name + "','" + sex + "','" + collage + "','" +zhi + "')");34 rs = stat.executeQuery("select * from a"); //查找data表

35 %>

36

37

38

39 if(rs.next())40 {41 out.print("

信息添加成功!

");42 }43 else{44 out.print("

信息添加失败!

");45 }46

47 %>

48

49

50

51 返回

52

53

54

55

56

57 if(rs != null)58 {59 rs.close(); //关闭结果集,但是rs还是有null值。

60 rs = null; //将rs滞空。

61 }62 if(stat != null)63 {64 stat.close(); //关闭stat。

65 stat = null; //滞空stat。

66 }67 if(conn != null)68 {69 conn.close(); //关闭数据库连接

70 conn = null;71 }72 %>

73

74

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

17

18

19

20 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

21 String num = request.getParameter("num");22 String name = request.getParameter("name");23 String sex = request.getParameter("sex");24 String cla = request.getParameter("cla");25 String collage = request.getParameter("collage");26

27 Connection conn = null; //定义静态数据库连接

28 Statement stat = null;29 ResultSet rs = null; //将rs滞空。

30 conn =S.getConnection();31 stat =conn.createStatement();32 //String sql = ;//向对应的数据字段添加数据

33 stat.executeUpdate("insert into b(num,name,sex,cla,collage) values('" +num34 + "','" + name + "','" + sex + "','" + cla + "','" +collage + "')");35 rs = stat.executeQuery("select * from b"); //查找data表

36 %>

37

38

39

40 if(rs.next())41 {42 out.print("

信息添加成功!

");43 }44 else{45 out.print("

信息添加失败!

");46 }47

48 %>

49

50

51

52 返回

53

54

55

56

57 if(rs != null)58 {59 rs.close(); //关闭结果集,但是rs还是有null值。

60 rs = null; //将rs滞空。

61 }62 if(stat != null)63 {64 stat.close(); //关闭stat。

65 stat = null; //滞空stat。

66 }67 if(conn != null)68 {69 conn.close(); //关闭数据库连接

70 conn = null;71 }72 %>

73

74

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

17

18

19

20 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

21 String num = request.getParameter("num");22 String name = request.getParameter("name");23 String shu = request.getParameter("shu");24 String ming = request.getParameter("ming");25 Connection conn = null; //定义静态数据库连接

26 Statement stat = null;27 ResultSet rs = null; //将rs滞空。

28 conn =S.getConnection();29 stat =conn.createStatement();30 //String sql = ;//向对应的数据字段添加数据

31 stat.executeUpdate("insert into c(num,name,shu,ming) values('" +num32 + "','" + name + "','" + shu + "','" +ming + "')");33 rs = stat.executeQuery("select * from c"); //查找data表

34 %>

35

36

37

38 if(rs.next())39 {40 out.print("

信息添加成功!

");41 }42 else{43 out.print("

信息添加失败!

");44 }45

46 %>

47

48

49

50 返回

51

52

53

54

55 if(rs != null)56 {57 rs.close(); //关闭结果集,但是rs还是有null值。

58 rs = null; //将rs滞空。

59 }60 if(stat != null)61 {62 stat.close(); //关闭stat。

63 stat = null; //滞空stat。

64 }65 if(conn != null)66 {67 conn.close(); //关闭数据库连接

68 conn = null;69 }70 %>

71

72

1

2 pageEncoding="UTF-8"%>

3

4

5

6

7

Welcome!

8

9

欢迎来到选课系统

10

11

12

13 修改个人信息

14 浏览课程信息

15 选课

16 返回

17

18

19

1

2 pageEncoding="UTF-8"%>

3

4

5

6

7

Welcome!

8

9

欢迎来到选课系统

10

11

12

13 修改个人信息

14 添加课程信息

15 浏览选课学生

16 返回

17

18

19

1

2

3

4

5

6

7 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

8 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

9 %>

10

11 String path = request.getContextPath(); //相对Path设置

12 String basePath = request.getScheme() + "://" + request.getServerName() + ":" +request.getServerPort()13 + path + "/"; //相对Path设置

14 %>

15

16

17

18

19

信息

20

21

22

23

24 function validate() {25 var num = document.forms[0].num.value; //创建变量name

26 var name = document.forms[0].name.value; //创建变量teacher

27 var sex = document.forms[0].sex.value;28 var collage = document.forms[0].collage.value; //创建变量address

29 var zhi = document.forms[0].zhi.value;30 if (name.length <= 0) { //判断姓名位数,必填

31 alert("姓名不能为空,请输入姓名!");32 return false;33 } else if (sex.length <= 0) { //判断学号位数,必填

34 alert("姓别不能为空,请输入姓别!");35 return false;36 }37

38

39 else{40 return true;41 }42 //document.getElementById("form").submit();

43 }44

45

46

47

48 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

49 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

50 String num = request.getParameter("num");51 String name = request.getParameter("name");52 String sex = request.getParameter("sex");53 String zhi = request.getParameter("zhi");54 String collage = request.getParameter("collage");55 Connection conn = null; //定义静态数据库连接

56 Statement stat = null; //滞空stat。

57 ResultSet rs = null; //将rs滞空。

58 conn =S.getConnection();59 stat =conn.createStatement();60 rs = stat.executeQuery("select * from a where name='" + name + "'"); //查找data表id字段

61 %>

62

63

教师信息

64


65

66

要修改的教师信息如下

67

68 style="font-size: 15pt; border: dashed 1pt">

69

70

工号

71

姓名

72

性别

73

学院

74

职称

75

76

77

78 while(rs.next()) {79 out.print("

");80 out.print("" + rs.getString("num") + ""); //输出name内容

81 out.print("

" + rs.getString("name") + ""); //输出gender内容

82 out.print("

" + rs.getString("sex") + "");83 out.print("" + rs.getString("collage") + ""); //输出major内容

84 out.print("

" + rs.getString("zhi") + "");85 out.print("");86 %>

87

88

89

90

将信息更改为:

91

92 onSubmit="return validate()">

93

94 工号:"

95 title="工号不能改变" onClick="return checkName(num)" readonly="readonly">

96

97

98 姓名:

99

100

101 性别:

102

103

104 学院:

105

106

107 职称:

108

109

110

111 返回添加信息页面

112

113 返回信息查询页面

114

115 }116 %>

117

118 if (rs != null) {119 rs.close(); //关闭结果集,但是rs还是有null值。

120 rs = null; //将rs滞空。

121 }122 if (stat != null) {123 stat.close(); //关闭stat。

124 stat = null; //滞空stat。

125 }126 if (conn != null) {127 conn.close(); //关闭数据库连接

128 conn = null;129 }130 %>

131

132

1

2

3

4

5

6

7 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

8 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

9 %>

10

11 String path = request.getContextPath(); //相对Path设置

12 String basePath = request.getScheme() + "://" + request.getServerName() + ":" +request.getServerPort()13 + path + "/"; //相对Path设置

14 %>

15

16

17

18

19

信息

20

21

22

23

24 function validate() {25

26 var num = document.forms[0].num.value; //创建变量name

27 var name = document.forms[0].name.value; //创建变量teacher

28 var sex = document.forms[0].sex.value;29 var collage = document.forms[0].collage.value; //创建变量address

30 var cla = document.forms[0].cla.value;31 if (name.length <= 0) { //判断姓名位数,必填

32 alert("姓名不能为空,请输入姓名!");33 return false;34 } else if (sex.length <= 0) { //判断学号位数,必填

35 alert("姓别不能为空,请输入姓别!");36 return false;37 }38

39

40 else{41 return true;42 }43 //document.getElementById("form").submit();

44 }45

46

47

48

49 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

50 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

51 String num = request.getParameter("num");52 String name = request.getParameter("name");53 String sex = request.getParameter("sex");54 String cla = request.getParameter("cla");55 String collage = request.getParameter("collage");56 Connection conn = null; //定义静态数据库连接

57 Statement stat = null; //滞空stat。

58 ResultSet rs = null; //将rs滞空。

59 conn =S.getConnection();60 stat =conn.createStatement();61 rs = stat.executeQuery("select * from b where name='" + name + "'"); //查找data表id字段

62 %>

63

64

学生信息

65


66

67

要修改的学生信息如下

68

69 style="font-size: 15pt; border: dashed 1pt">

70

71

学号

72

姓名

73

性别

74

班级

75

学院

76

77

78

79 while(rs.next()) {80 out.print("

");81 out.print("" + rs.getString("num") + ""); //输出name内容

82 out.print("

" + rs.getString("name") + ""); //输出gender内容

83 out.print("

" + rs.getString("sex") + "");84 out.print("" + rs.getString("cla") + ""); //输出major内容

85 out.print("

" + rs.getString("collage") + "");86 out.print("");87 %>

88

89

90

91

将信息更改为:

92

93 onSubmit="return validate()">

94

95 学号:"

96 title="学号不能改变" onClick="return checkName(num)" readonly="readonly">

97

98

99 姓名:

100

101

102 性别:

103

104

105 班级:

106

107

108 学院:

109

110

111

112 返回添加信息页面

113

114 返回信息查询页面

115

116 }117 %>

118

119 if (rs != null) {120 rs.close(); //关闭结果集,但是rs还是有null值。

121 rs = null; //将rs滞空。

122 }123 if (stat != null) {124 stat.close(); //关闭stat。

125 stat = null; //滞空stat。

126 }127 if (conn != null) {128 conn.close(); //关闭数据库连接

129 conn = null;130 }131 %>

132

133

1

2

3

4

5 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

6 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

7 %>

8

9 String path = request.getContextPath(); //相对Path设置

10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

11 %>

12

13

14

15

16

按姓名条件查询

17

18

19

20 String name = request.getParameter("name");21 Connection conn = null; //定义静态数据库连接

22 Statement stat = null; //滞空stat。

23 ResultSet rs = null; //将rs滞空。

24 conn =S.getConnection();25 stat =conn.createStatement();26 rs = stat.executeQuery("select * from c where name like '%" + name + "%'");//查找data表name字段

27 %>

28

29

符合条件的信息

30


31

32

33

34

课程编号

35

课程名称

36

选课人数

37

任课教师

38

39

40

41 while(rs.next())42 {43 out.print("

");44 out.print("" + rs.getString("num") + ""); //输出name内容

45 out.print("

" + rs.getString("name") + ""); //输出gender内容

46 out.print("

" + rs.getString("shu") + "");47 out.print("" + rs.getString("ming") + ""); //输出major内容

48 %>

49

50

51 out.print("

");52 }53

54 %>

55

56

57 选课

58

59 if(rs != null)60 {61 rs.close(); //关闭结果集,但是rs还是有null值。

62 rs = null; //将rs滞空。

63 }64 if(stat != null) //判断stat是否滞空。

65 {66 stat.close(); //关闭stat。

67 stat = null; //滞空stat。

68 }69 if(conn != null)70 {71 conn.close(); //关闭数据库连接

72 conn = null;73 }74 %>

75

76

77

78

79

80

81 request.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

82 response.setCharacterEncoding("UTF-8"); //设置响应的编码为UTF-8

83 %>

84

85 String path = request.getContextPath(); //相对Path设置

86 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; //相对Path设置

87 %>

88

89

90

91

92

按姓名条件查询

93

94

95

96 String name = request.getParameter("name");97 Connection conn = null; //定义静态数据库连接

98 Statement stat = null; //滞空stat。

99 ResultSet rs = null; //将rs滞空。

100 conn =S.getConnection();101 stat =conn.createStatement();102 rs = stat.executeQuery("select * from c where name like '%" + name + "%'");//查找data表name字段

103 %>

104

105

符合条件的信息

106


107

108

109

110

课程编号

111

课程名称

112

选课人数

113

任课教师

114

115

116

117 while(rs.next())118 {119 out.print("

");120 out.print("" + rs.getString("num") + ""); //输出name内容

121 out.print("

" + rs.getString("name") + ""); //输出gender内容

122 out.print("

" + rs.getString("shu") + "");123 out.print("" + rs.getString("ming") + ""); //输出major内容

124 %>

125

126

127 out.print("

");128 }129

130 %>

131

132

133 选课

134

135 if(rs != null)136 {137 rs.close(); //关闭结果集,但是rs还是有null值。

138 rs = null; //将rs滞空。

139 }140 if(stat != null) //判断stat是否滞空。

141 {142 stat.close(); //关闭stat。

143 stat = null; //滞空stat。

144 }145 if(conn != null)146 {147 conn.close(); //关闭数据库连接

148 conn = null;149 }150 %>

151

152

153

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值