16.教师-学生管理-查询学生信息
17.管理员-主页面
18.管理员-个人信息
19.管理员-课程管理-课程信息查看
20.管理员-课程管理-添加课程信息
21.管理员-成绩管理-成绩信息查看
22.管理员-成绩管理-添加学生成绩
23.管理员-成绩管理-学生总成绩
24.管理员-教师管理-查询教师信息
25.管理员-教师管理-添加教师信息
26.管理员-学生管理-查询学生信息
27.管理员-学生管理-添加学生信息
28.管理员-查询所有账号
三、部分代码
CourseDaoImpl
package dao.Impl; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.text.DateFormat; import java.util.ArrayList; import java.util.List; import model.Course; import model.PageBean; import dao.CourseDao; import db.DBCon; public class CourseDaoImpl implements CourseDao { private DBCon dbCon = new DBCon(); private Course course; private PageBean pageBean; public int addCos(Course course, String courseDate) { System.out.println(courseDate); // Date courseDate=(Date) course.getCourseDate(); // DateFormat // data=DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM); String sql = "insert into course(course_name,course_credit,course_hours,course_teacher,coursedate) values('" + course.getCourseName() + "'," + course.getCourseCredit() + "," + course.getCourseHours() + ",'" + course.getCourseTeacher() + "',DATE('" + courseDate + "'))"; int rs = dbCon.query(sql); return rs; } public int deleteCos(int courseID) { String sql = "delete from course where course_id=" + courseID; int rs = dbCon.query(sql); return rs; } public int editCos(Course course, String courseDate) { String sql = "update course set course_name='" + course.getCourseName() + "',course_credit=" + course.getCourseCredit() + ",course_hours=" + course.getCourseHours() + ",course_teacher='" + course.getCourseTeacher() + "',coursedate=DATE('" + courseDate + "') where course_id=" + course.getCourseID(); int rs = dbCon.query(sql); return rs; } public List findAll() { List<Course> list = new ArrayList<Course>(); String sql = "select * from course"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int courseID = rs.getInt("course_id"); String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); Date courseDate = rs.getDate("coursedate"); course = new Course(courseID, courseName, courseCredit, courseHours, courseTea, courseDate); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List findOne(int courseID) { List<Course> list = new ArrayList<Course>(); String sql = "select * from course where course_id=" + courseID; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int courseid = rs.getInt("course_id"); String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); Date courseDate = rs.getDate("coursedate"); course = new Course(courseid, courseName, courseCredit, courseHours, courseTea, courseDate); list.add(course); } } catch (SQLException e) { e.printStackTrace(); } return list; } public Course selectOneCos(Course cours) { String sql = "select * from course where course_name='" + cours.getCourseName() + "' and course_teacher='" + cours.getCourseTeacher() + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int courseid = rs.getInt("course_id"); String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); Date courseDate = rs.getDate("coursedate"); course = new Course(courseid, courseName, courseCredit, courseHours, courseTea, courseDate); } } catch (SQLException e) { e.printStackTrace(); } return course; } public PageBean courseListPage(int pageNo, int pageCount) { int totalCount=0; List<Course> list = new ArrayList<Course>(); String sql = "select * from course limit "+((pageNo-1)*pageCount)+","+pageCount; String sqlCount="select count(*) from course"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int courseID = rs.getInt("course_id"); String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); Date courseDate = rs.getDate("coursedate"); course = new Course(courseID, courseName, courseCredit, courseHours, courseTea, courseDate); list.add(course); } rs=dbCon.find(sqlCount); while(rs.next()){ totalCount=rs.getInt(1); } pageBean=new PageBean(list,totalCount,pageNo,pageCount); } catch (SQLException e) { e.printStackTrace(); } return pageBean; } }
ScoreDaoImpl
package dao.Impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; import model.PageBean; import model.Score; import model.ScoreCou; import model.ScoreSum; import dao.ScoreDao; import db.DBCon; public class ScoreDaoImpl implements ScoreDao { private Score score = null; private ScoreCou scoreCou = null; private PageBean pageBean = null; private ScoreSum scoreSum = null; private DBCon dbCon = new DBCon(); public int addScore(Score score) { String sql = "insert into score(stu_num,stu_name,stu_class,course_name,score_grade,major) values('" + score.getStuNum() + "','" + score.getStuName() + "','" + score.getStuClass() + "','" + score.getCourseName() + "'," + score.getScoreGrade() + ",'" + score.getMajor() + "')"; int rs = dbCon.query(sql); return rs; } public int deleteScore(int scoreID) { String sql = "delete from score where score_id=" + scoreID; int rs = dbCon.query(sql); return rs; } public int editCos(Score score) { String sql = "update score set stu_num='" + score.getStuNum() + "',stu_name='" + score.getStuName() + "',stu_class='" + score.getStuClass() + "',course_name='" + score.getCourseName() + "',score_grade=" + score.getScoreGrade() + ",major='" + score.getMajor() + "' where score_id=" + score.getScoreID(); int rs = dbCon.query(sql); return rs; } public List findAll() { List<Score> list = new ArrayList<Score>(); String sql = "select * from score"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreID = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); Score score = new Score(scoreID, stuNum, stuName, stuClass, courseName, scoreGrade, major); list.add(score); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List findOne(String stuNum) { List<ScoreCou> list = new ArrayList<ScoreCou>(); String sql = "select score.course_name,course_credit,course_hours,course_teacher,major,coursedate,score_grade " + "from score,course where score.course_name=course.course_name and stu_num='" + stuNum + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); String major = rs.getString("major"); Date courseDate = rs.getDate("coursedate"); double scoreGrade = rs.getDouble("score_grade"); ScoreCou scoreCou = new ScoreCou(courseName, courseCredit, courseHours, courseTea, major, courseDate, scoreGrade); list.add(scoreCou); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List selectScore(int scoreID) { List<Score> list = new ArrayList<Score>(); String sql = "select * from score where score_id=" + scoreID; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreid = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); Score score = new Score(scoreid, stuNum, stuName, stuClass, courseName, scoreGrade, major); list.add(score); } } catch (SQLException e) { e.printStackTrace(); } return list; } public Score selectScoreInfo(Score scor) { String sql = "select * from score where stu_num='" + scor.getStuNum() + "' and course_name='" + scor.getCourseName() + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreid = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); score = new Score(scoreid, stuNum, stuName, stuClass, courseName, scoreGrade, major); } } catch (SQLException e) { e.printStackTrace(); } return score; } public PageBean scoreListPage(int pageNo, int pageCount, String stuNum) { int totalCount = 0; List<ScoreCou> list = new ArrayList<ScoreCou>(); String sql = "select score.course_name,course_credit,course_hours,course_teacher,major,coursedate,score_grade " + "from score,course where score.course_name=course.course_name and stu_num='" + stuNum + "' limit " + ((pageNo - 1) * pageCount) + "," + pageCount; String sqlCount = "select count(*) from score,course where score.course_name=course.course_name and stu_num='" + stuNum + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { String courseName = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); String major = rs.getString("major"); Date courseDate = rs.getDate("coursedate"); double scoreGrade = rs.getDouble("score_grade"); ScoreCou scoreCou = new ScoreCou(courseName, courseCredit, courseHours, courseTea, major, courseDate, scoreGrade); list.add(scoreCou); } rs = dbCon.find(sqlCount); while (rs.next()) { totalCount = rs.getInt(1); } pageBean = new PageBean(list, totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } public PageBean scoreListPage(int pageNo, int pageCount) { int totalCount = 0; List<Score> list = new ArrayList<Score>(); String sql = "select * from score limit " + ((pageNo - 1) * pageCount) + "," + pageCount; String sqlCount = "select count(*) from score"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreID = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); score = new Score(scoreID, stuNum, stuName, stuClass, courseName, scoreGrade, major); list.add(score); } rs = dbCon.find(sqlCount); while (rs.next()) { totalCount = rs.getInt(1); } pageBean = new PageBean(list, totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } public List findStuOne(String stuNum, String courseName) { List<ScoreCou> list = new ArrayList<ScoreCou>(); String sql = "select score.course_name,course_credit,course_hours,course_teacher,major,coursedate,score_grade " + "from score,course where score.course_name=course.course_name and stu_num='" + stuNum + "' and course.course_name='" + courseName + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { String coursename = rs.getString("course_name"); int courseCredit = rs.getInt("course_credit"); int courseHours = rs.getInt("course_hours"); String courseTea = rs.getString("course_teacher"); String major = rs.getString("major"); Date courseDate = rs.getDate("coursedate"); double scoreGrade = rs.getDouble("score_grade"); scoreCou = new ScoreCou(coursename, courseCredit, courseHours, courseTea, major, courseDate, scoreGrade); list.add(scoreCou); } } catch (SQLException e) { e.printStackTrace(); } return list; } public PageBean selectScoreSum(int pageNo, int pageCount) { int totalCount = 0; int i = 1; List<ScoreSum> list = new ArrayList<ScoreSum>(); String sql = "select score.stu_num,score.stu_name,score.stu_class,score.major, sum(score.score_grade) as total,avg(score.score_grade) as avg " + "from score group by score.stu_num order by total DESC limit " + ((pageNo - 1) * pageCount) + "," + pageCount; String sqlCount = "select count(*) from (select stu_num from score group by score.stu_num ) as a"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int number = i; String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String major = rs.getString("major"); double total = rs.getDouble("total"); double avg = rs.getDouble("avg"); scoreSum = new ScoreSum(number, stuNum, stuName, stuClass, major, total, avg); list.add(scoreSum); i++; } rs = dbCon.find(sqlCount); while (rs.next()) { totalCount = rs.getInt(1); } pageBean = new PageBean(list, totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } public PageBean selectStuScore(int pageNo, int pageCount, Score score) { int totalCount = 0; List<Score> list = new ArrayList<Score>(); String sql = "select * from score where stu_num like '%" + score.getStuNum() + "%' and course_name like '%" + score.getCourseName() + "%' and stu_name like '%" + score.getStuName() + "%' and stu_class like '%" + score.getStuClass() + "%' and major like '%" + score.getMajor() + "%' limit " + ((pageNo - 1) * pageCount) + "," + pageCount; String sqlCount = "select count(*) from score where stu_num like '%" + score.getStuNum() + "%' and course_name like '%" + score.getCourseName() + "%' and stu_name like '%" + score.getStuName() + "%' and stu_class like '%" + score.getStuClass() + "%' and major like '%" + score.getMajor() + "%'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreID = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); score = new Score(scoreID, stuNum, stuName, stuClass, courseName, scoreGrade, major); list.add(score); } rs = dbCon.find(sqlCount); while (rs.next()) { totalCount = rs.getInt(1); } pageBean = new PageBean(list, totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } public PageBean selectTeaScore(int pageNo, int pageCount, String teaName, Score score) { int totalCount = 0; List<Score> list = new ArrayList<Score>(); String sql = "select score.score_id,score.stu_num,score.stu_name,score.stu_class,score.course_name,score.score_grade,score.major from score,course where score.course_name=course.course_name and course.course_teacher='" + teaName + "' and score.stu_name like '%" + score.getStuName() + "%' and score.stu_class like '%" + score.getStuClass() + "%' and score.stu_num like '%" + score.getStuNum() + "%' limit " + ((pageNo - 1) * pageCount) + "," + pageCount; String sqlCount = "select count(*) from score,course where score.course_name=course.course_name and course.course_teacher='" + teaName + "' and score.stu_name like '%" + score.getStuName() + "%' and score.stu_class like '%" + score.getStuClass() + "%' and score.stu_num like '%" + score.getStuNum() + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int scoreID = rs.getInt("score_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuClass = rs.getString("stu_class"); String courseName = rs.getString("course_name"); double scoreGrade = rs.getDouble("score_grade"); String major = rs.getString("major"); score = new Score(scoreID, stuNum, stuName, stuClass, courseName, scoreGrade, major); list.add(score); } rs = dbCon.find(sqlCount); while (rs.next()) { totalCount = rs.getInt(1); } pageBean = new PageBean(list, totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } }
StudentDaoImpl
package dao.Impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import model.PageBean; import model.Student; import dao.StudentDao; import db.DBCon; public class StudentDaoImpl implements StudentDao { private DBCon dbCon = new DBCon(); private Student student; private PageBean pageBean; public int addStu(Student student) { String sql = "insert into student(stu_num,stu_name,stu_sex,stu_age,stu_class,major,department) values('" + student.getStuNum() + "','" + student.getStuName() + "','" + student.getStuSex() + "'," + student.getStuAge() + ",'" + student.getStuClass() + "','" + student.getMajor() + "','" + student.getDepartment() + "')"; int rs = dbCon.query(sql); return rs; } public int deleteStu(String stuNum) { String sql = "delete from student where stu_num='" + stuNum + "'"; int rs = dbCon.query(sql); return rs; } public int editStu(Student student) { String sql = "update student set stu_name='" + student.getStuName() + "',stu_sex='" + student.getStuSex() + "',stu_age=" + student.getStuAge() + ",stu_class='" + student.getStuClass() + "',major='" + student.getMajor() + "',department='" + student.getDepartment() + "' where stu_num='" + student.getStuNum() + "'"; int rs=dbCon.query(sql); return rs; } public List findAll() { List<Student> list = new ArrayList<Student>(); String sql = "select * from student"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int stuID = rs.getInt("stu_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuSex = rs.getString("stu_sex"); int stuAge = rs.getInt("stu_age"); String stuClass = rs.getString("stu_class"); String major = rs.getString("major"); String department = rs.getString("department"); student = new Student(stuID, stuNum, stuName, stuSex, stuAge, stuClass, major, department); list.add(student); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List findOne(String stuNum) { List<Student> list = new ArrayList<Student>(); String sql="select * from student where stu_num='"+stuNum+"'"; ResultSet rs=dbCon.find(sql); try { while(rs.next()){ int stuID = rs.getInt("stu_id"); String stunum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuSex = rs.getString("stu_sex"); int stuAge = rs.getInt("stu_age"); String stuClass = rs.getString("stu_class"); String major = rs.getString("major"); String department = rs.getString("department"); student = new Student(stuID, stunum, stuName, stuSex, stuAge, stuClass, major, department); list.add(student); } } catch (SQLException e) { e.printStackTrace(); } return list; } //pageNo当前页码,pageCount每页显示总条数 public PageBean stuListPage(int pageNo, int pageCount) { int totalCount=0; List<Student> list = new ArrayList<Student>(); String sql="select * from student limit "+((pageNo-1)*pageCount)+","+pageCount; String sqlCount="select count(*) from student"; try { ResultSet rs=dbCon.find(sql); while(rs.next()){ int stuID = rs.getInt("stu_id"); String stuNum = rs.getString("stu_num"); String stuName = rs.getString("stu_name"); String stuSex = rs.getString("stu_sex"); int stuAge = rs.getInt("stu_age"); String stuClass = rs.getString("stu_class"); String major = rs.getString("major"); String department = rs.getString("department"); student = new Student(stuID, stuNum, stuName, stuSex, stuAge, stuClass, major, department); list.add(student); } rs=dbCon.find(sqlCount); while(rs.next()){ totalCount=rs.getInt(1); } pageBean=new PageBean(list , totalCount, pageNo, pageCount); } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } return pageBean; } }
TeacherDaoImpl
package dao.Impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import model.PageBean; import model.Student; import model.Teacher; import dao.TeacherDao; import db.DBCon; public class TeacherDaoImpl implements TeacherDao{ private DBCon dbCon = new DBCon(); private Teacher teacher; private PageBean pageBean; public int addTea(Teacher teacher) { String sql = "insert into teacher(tea_num,tea_name,tea_sex,tea_age,tea_course,major,department) values('" + teacher.getTeaNum() + "','" + teacher.getTeaName() + "','" + teacher.getTeaSex() + "'," + teacher.getTeaAge() + ",'" + teacher.getTeaCourse() + "','" + teacher.getMajor() + "','" + teacher.getDepartment() + "')"; int rs = dbCon.query(sql); return rs; } public int deleteTea(String teaNum) { String sql = "delete from teacher where tea_num='" + teaNum + "'"; int rs = dbCon.query(sql); return rs; } public int editTea(Teacher teacher) { String sql = "update teacher set tea_name='" + teacher.getTeaName() + "',tea_sex='" + teacher.getTeaSex() + "',tea_age=" + teacher.getTeaAge() + ",tea_course='" + teacher.getTeaCourse() + "',major='" + teacher.getMajor() + "',department='" + teacher.getDepartment() + "' where tea_num='" + teacher.getTeaNum() + "'"; int rs=dbCon.query(sql); return rs; } public List findAll() { List<Teacher> list=new ArrayList<Teacher>(); String sql="select * from teacher"; ResultSet rs=dbCon.find(sql); try { while (rs.next()) { int teaID = rs.getInt("tea_id"); String teaNum = rs.getString("tea_num"); String teaName = rs.getString("tea_name"); String teaSex = rs.getString("tea_sex"); int teaAge = rs.getInt("tea_age"); String teaCourse = rs.getString("tea_course"); String major = rs.getString("major"); String department = rs.getString("department"); teacher = new Teacher(teaID, teaNum, teaName, teaSex, teaAge, teaCourse, major, department); list.add(teacher); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List findOne(String teaNum) { List<Teacher> list=new ArrayList<Teacher>(); String sql="select * from teacher where tea_num='"+teaNum+"'"; ResultSet rs=dbCon.find(sql); try { while (rs.next()) { int teaID = rs.getInt("tea_id"); String teanum = rs.getString("tea_num"); String teaName = rs.getString("tea_name"); String teaSex = rs.getString("tea_sex"); int teaAge = rs.getInt("tea_age"); String teaCourse = rs.getString("tea_course"); String major = rs.getString("major"); String department = rs.getString("department"); teacher = new Teacher(teaID, teanum, teaName, teaSex, teaAge, teaCourse, major, department); list.add(teacher); } } catch (SQLException e) { e.printStackTrace(); } return list; } public PageBean teaListPage(int pageNo, int pageCount) { List<Teacher> list=new ArrayList<Teacher>(); int totalCount=0; String sql="select * from teacher limit "+((pageNo-1)*totalCount)+","+totalCount; String sqlCount="select count(*) from teacher"; ResultSet rs=dbCon.find(sql); try { while(rs.next()){ int teaID = rs.getInt("tea_id"); String teanum = rs.getString("tea_num"); String teaName = rs.getString("tea_name"); String teaSex = rs.getString("tea_sex"); int teaAge = rs.getInt("tea_age"); String teaCourse = rs.getString("tea_course"); String major = rs.getString("major"); String department = rs.getString("department"); teacher = new Teacher(teaID, teanum, teaName, teaSex, teaAge, teaCourse, major, department); list.add(teacher); } rs=dbCon.find(sqlCount); while(rs.next()){ totalCount=rs.getInt(1); } } catch (SQLException e) { dbCon.close(); e.printStackTrace(); } pageBean=new PageBean(list,totalCount,pageNo,pageCount); return pageBean; } }
UserDaoImpl
package dao.Impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import model.UsRole; import model.User; import dao.UserDao; import db.DBCon; public class UserDaoImpl implements UserDao { private DBCon dbCon = new DBCon(); private User user; private UsRole usRole; public User login(User user) { String sql = "select *from user where user_num='" + user.getUserNum() + "'"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int userID = rs.getInt("user_id"); String userNum = rs.getString("user_num"); String userName = rs.getString("user_name"); String pwd = rs.getString("password"); String phone = rs.getString("phone"); int roleID = rs.getInt("role_id"); user = new User(userID, userNum, userName, pwd, phone, roleID); } } catch (SQLException e) { e.printStackTrace(); } return user; } public int editPwd(User user) { String sql = "update user set password='" + user.getPassword() + "' where user_num='" + user.getUserNum() + "'"; int rs = dbCon.query(sql); return rs; } public int addUser(User user) { String sql = "insert into user(user_num,user_name,password,phone,role_id) values('" + user.getUserNum() + "','" + user.getUserName() + "','" + user.getPassword() + "'," + user.getPhone() + "," + user.getRoleID() + ")"; int rs = dbCon.query(sql); return rs; } public List findAll() { List<UsRole> list = new ArrayList<UsRole>(); String sql = "select user_id,user_num,user_name,password,phone,role_name from user,role where user.role_id=role.role_id"; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int userID = rs.getInt("user_id"); String userNum = rs.getString("user_num"); String userName = rs.getString("user_name"); String pwd = rs.getString("password"); String phone = rs.getString("phone"); String roleName = rs.getString("role_name"); usRole = new UsRole(userID, userNum, userName, pwd, phone, roleName); list.add(usRole); } } catch (SQLException e) { e.printStackTrace(); } return list; } public List selectOneUser(int userID) { List<User> list = new ArrayList<User>(); String sql = "select * from user where user_id=" + userID; ResultSet rs = dbCon.find(sql); try { while (rs.next()) { int userid = rs.getInt("user_id"); String userNum = rs.getString("user_num"); String userName = rs.getString("user_name"); String pwd = rs.getString("password"); String phone = rs.getString("phone"); int roleID = rs.getInt("role_id"); user = new User(userID, userNum, userName, pwd, phone, roleID); list.add(user); } } catch (SQLException e) { e.printStackTrace(); } return list; } public int editUser(User user) { String sql = "update user set user_name='" + user.getUserName() + "',password=" + user.getPassword() + ",phone='" + user.getPhone() + "' where user_num='" + user.getUserNum() + "'"; int rs = dbCon.query(sql); return rs; } }
DBCon
package db; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class DBCon { Connection con = null; Statement st = null; ResultSet rs = null; String driver=null; String url = null; String username = null; String password = null; public Connection dbCon() { try { InputStream is=DBCon.class.getClassLoader().getResourceAsStream("db.properties"); Properties prop=new Properties(); try { prop.load(is); driver=prop.getProperty("driver"); url=prop.getProperty("url"); username=prop.getProperty("username"); password=prop.getProperty("password"); } catch (IOException e1) { e1.printStackTrace(); } Class.forName(driver); /*Class.forName("com.mysql.jdbc.Driver"); url = "jdbc:mysql:///sams?useUnicode=true&characterEncoding=utf8"; username = "root"; password = "root";*/ try { con = DriverManager.getConnection(url, username, password); } catch (SQLException e) { e.printStackTrace(); } } catch (ClassNotFoundException e) { e.printStackTrace(); } return con; } /* * 增删改 */ public int query(String sql) { int rs = 0; con = dbCon(); try { st = con.createStatement(); rs = st.executeUpdate(sql); } catch (SQLException e) { close(); e.printStackTrace(); } return rs; } /* * 查 */ public ResultSet find(String sql) { try { con = dbCon(); st = con.createStatement(); rs = st.executeQuery(sql); } catch (SQLException e) { close(); e.printStackTrace(); } return rs; } /* * 关闭数据库 */ public void close() { try { if (rs != null) rs.close(); if (st != null) st.close(); if (con != null) con.close(); } catch (SQLException e) { e.printStackTrace(); } } }
register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>注册页面</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> </head> <style type="text/css"> html, body { margin: 0; padding: 0; width: 100%; height: 100%; background-image: linear-gradient(to bottom, #243949 0%, #517fa4 100%); overflow: hidden; } canvas{ position: absolute; top: 0; } .div_ads { z-index: 3; width: 30%; margin: 0 auto; margin-top: 50px; border: 1px solid #ccc; background: rgba(238, 235, 235,1); position: relative; border-radius: 6px; height: 650px; } table { position: absolute; left: 10%; } table tr td { text-align: center; height:44px; width: 8%; text-align: center; } h3{ text-align: center; padding-top: 20px; } hr{ margin-left: 15px; margin-right: 15px; background: #ccc; } .btn1{ background: #afc5d6; } font{ font-size: .7rem; float: left; } </style> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="js/jquery-3.3.1.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/particle-bg.umd.min.js"></script> <script type="text/javascript"> window.onload = function(){ particleBg('body', { color: 'rgba(255, 255, 255, 0.5)' }); } </script> <script type="text/javascript"> function AjaxChecked(){ var xmlHttpRequest=null; if(XMLHttpRequest){ xmlHttpRequest=new XMLHttpRequest(); }else{ xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP"); } if(xmlHttpRequest!=null){ //拿到账号 var stuNum=document.getElementById("stuNum"); if(stuNum.value==""){ document.getElementById("stuNumcheck").innerHTML = "学号不能为空"; return; }else{ var url="ServletRegisterStu?stuNum="+stuNum.value; xmlHttpRequest.open("get",url,true); xmlHttpRequest.send(); xmlHttpRequest.onreadystatechange=function(){ if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200){ var text = xmlHttpRequest.responseText; //alert(text); document.getElementById("stuNumcheck").innerHTML = text; } }; } } } function namecheck(){ var stuName=document.getElementById("stuName").value; var rename=/^[一-龥]+$/gi; //中文判断 if(stuName==""){ document.getElementById("stuNamecheck").innerHTML = "用户名不能为空"; } else if (!rename.test(stuName)) { document.getElementById("stuNamecheck").innerHTML = "请输入中文名,如:王文军"; }else{ document.getElementById("stuNamecheck").innerHTML = "正确"; } } function pwdcheck(){ var pwd1=document.getElementById("password").value; if(pwd1==""){ document.getElementById("stuPwdcheck").innerHTML = "密码不能为空"; }else if(pwd1.length<6){ document.getElementById("stuPwdcheck").innerHTML = "密码不能小于六位"; }else { document.getElementById("stuPwdcheck").innerHTML = "正确"; } } function pwdc(){ var pwd1=document.getElementById("password").value; var pwd2=document.getElementById("pwd").value; if(pwd1==""){ document.getElementById("stuPwdrcheck").innerHTML = "确认密码不能为空"; }else if(pwd1!=pwd2){ document.getElementById("stuPwdrcheck").innerHTML = "两次密码不一致"; }else { document.getElementById("stuPwdrcheck").innerHTML = "正确"; } } </script> </head> <body> <form action="ServletRegistersStudent" method="post"> <div class="div_ads"> <font>${msg}</font><h3>注册页面</h3> <hr class="color:black"> <table> <tr> <td colspan="2"><input type="text" name="stuNum" class="put form-control" id="stuNum" onblur="AjaxChecked();" placeholder="学号" aria-describedby="basic-addon1"/></td> <td><font id="stuNumcheck"></font></td> </tr> <tr> <td colspan="2"><input type="text" name="stuName" class="put form-control" id="stuName" onblur="namecheck();" placeholder="姓名" aria-describedby="basic-addon1"/></td> <td><font id="stuNamecheck"></font></td> </tr> <tr> <td colspan="2"><input type="password" name="password" class="put form-control" id="password" onblur="pwdcheck();" placeholder="密码" aria-describedby="basic-addon1"/></td> <td><font id="stuPwdcheck"></font></td> </tr> <tr> <td colspan="2"><input type="password" name="pwd" class="put form-control" id="pwd" onblur="pwdc();" placeholder="确认密码" aria-describedby="basic-addon1"/></td> <td><font id="stuPwdrcheck"></font></td> </tr> <tr> <td colspan="2"><input type="radio" name="stuSex" value="男" checked="checked" />男 <input type="radio" name="stuSex" value="女" />女 </td> </tr> <tr> <td colspan="2"><input type="text" name="stuAge" class="put form-control" placeholder="年龄" aria-describedby="basic-addon1"/></td> </tr> <tr> <td colspan="2"><input type="text" name="stuClass" class="put form-control" placeholder="班级" aria-describedby="basic-addon1"/></td> </tr> <tr> <td colspan="2"><input type="text" name="major" class="put form-control" placeholder="专业" aria-describedby="basic-addon1"/></td> </tr> <tr> <td colspan="2"><input type="text" name="department" class="put form-control" placeholder="院系" aria-describedby="basic-addon1"/></td> </tr> <tr> <td colspan="2"><input type="text" name="phone" class="put form-control" placeholder="电话" aria-describedby="basic-addon1"/></td> </tr> <tr> <td colspan="2"><input type="hidden" name="role" value="0" /></td> </tr> <tr> <td><input type="submit" value="注册" class="putb btn btn1" /></td> <td><input type="reset" value="清空" class="putb btn btn1" /></td> </tr> </table> </div> </form> </body> </html>
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>登陆</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <style type="text/css"> html, body { margin: 0; padding: 0; width: 100%; height: 100%; background-image: linear-gradient(to bottom, #243949 0%, #517fa4 100%); overflow: hidden; } canvas{ position: absolute; top: 0; z-index: -1; } #_top { text-align: center; height: 100px; font-size: 30px; padding-top: 30px; letter-spacing: 10px; /*字与字之间的间距*/ } #_top span{ color: aliceblue; } .div_body { height: 400px; width: 30%; margin: 10% auto; position: relative; /*background:rgba(255,255,255, 0.3);*/ background: #fff; /*box-shadow: whitesmoke 5px 5px 50px 5px;*/ border-radius: 6px; z-index: 2; } #_body { width: 100%; text-align: center; } .msg{ padding-top: 20px; color: #374b5d; height: 40px; } table{ margin: 0 10%; width: 100%; height: 85%; } table tr{ width: 100%; height: 15%; } table tr td{ font-size: 20px; width: 100%; } .input{ width: 80%; height: 55%; border-radius: 10px; text-align: center; font-size: 15px; border:1px solid #ccc; color: #ccc; } .btn { color: #ffffff; background-color: #40586d; border-color: #374b5d; width:20%; margin-right: 8%; } .check{ width: 13%; } </style> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <script src="js/jquery-3.3.1.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/particle-bg.umd.min.js"></script> <script type="text/javaScript"> window.onload = function() { particleBg('body', { color: 'rgba(255, 255, 255, 0.5)' }); } </script> </head> <body> <div class="div_body"> <div id="_body"> <h3 class="msg" style="cursor:default">${massage }</h3> <form action="ServletLogin" method="post" onsubmit="return checked(this)"> <table> <tr> <td><input class="input" type="text" name="ID" placeholder="账号"> </td> </tr> <tr> <td><input class="input" type="password" name="pwd" placeholder="密码"> </td> </tr> <tr> <td> <input class="check" type="radio" name="role" value="0" checked="checked">学生 <input class="check" type="radio" name="role" value="1">教师 <input class="check" type="radio" name="role" value="2">管理员 </td> </tr> <tr> <td> <input class="btn" type="submit" value="登录"> <input class="btn" type="button" name="register" value="注册" onclick="window.open('register/register.jsp')"> <input class="btn" type="reset" value="取消"> </td> </tr> </table> </form> </div> </div> </body> </html>
selectScore.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title></title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <style type="text/css"> .div_select,.div_ads { width:75%; margin: auto; margin-top: 50px; margin-left:20%; } .attr{ font:bold; } a{ cursor: pointer } #form1{ width:200px; display: inline-block } #pageNo{ width:200px; display: inline-block } </style> <link rel="stylesheet" href="css/bootstrap.min.css"> <script type="text/javascript"> function page(s){ var frm=document.getElementById("frm"); var pageNo=document.getElementById("pageNo"); pageNo.value=s; frm.submit(); } </script> </head> <body> <div class="div_select"> <form action="ServletOneStudentScore" method="post"> 课程名:<input type="text" class="form-control" id="form1" name="cosName"/> <input type="submit" class="btn btn-primary" value="查询" /> </form> </div> <form action="ServletFindStudentScore" method="post" id="frm"></form> <div class="div_ads"> <div class="panel panel-default"> <!-- Default panel contents --> <div class="panel-heading"> 成绩信息 </div> <!-- Table --> <table class="table" style="width: 100%"> <tr> <td><b>科目</b></td> <td><b>学分</b></td> <td><b>学时</b></td> <td><b>任课教师</b></td> <td><b>专业</b></td> <td><b>开课时间</b></td> <td><b>成绩</b></td> </tr> <c:forEach var="list" items="${list.pbjs }"> <tr> <td>${list.getCourseName() }</td> <td>${list.getCourseCredit() }</td> <td>${list.getCourseHours() }</td> <td>${list.getCourseTeacher() }</td> <td>${list.getMajor() }</td> <td>${list.getCourseDate() }</td> <td>${list.getScoreGrade() }</td> </tr> </c:forEach> <tr> <td colspan="7"><a onclick="page(1);">首页</a> <c:if test="${list.isPrevious() }"> <a onclick="page(${list.pageNo-1});">上一页</a> </c:if> <c:if test="${list.isNext() }"> <a onclick="page(${list.pageNo+1});">下一页</a> </c:if> <a onclick="page(${list.totalPage });">最后一页</a> <br /> 跳转到:<input id="pageNo" type="text" class="form-control form1" name="pageNo" value="${list.pageNo }" /> 每页记录数:<input type="text" name="pageCount" class="form-control" id="form1" value="${list.pageCount }" /> <input type="hidden" name="totalPage" value="${list.totalPage }" id='form1' /> <input type="submit" class="btn btn-primary" value="跳转" /> 共有${list.totalPage }页</td> </tr> </table> </div> </div> </form> <script src="js/jquery-3.3.1.min.js"></script> <script src="js/bootstrap.min.js"></script> </body> </html>
四、其他
1.其他系统实现
1.JavaWeb系统系列实现
Java+Springboot+Mybatis+Bootstrap+Maven实现网上商城系统
2.JavaSwing系统系列实现
2.获取源码
点击以下链接获取源码,数据库文件在sql文件下面。
Java+Servlet+JSP+Bootstrap+Mysql学生成绩管理系统源码
3.运行项目
请点击以下链接,部署你的项目。
4.备注
如有侵权请联系我删除。
5.支持博主
如果您觉得此文对您有帮助,请点赞加关注。祝您生活愉快!想要获取其他资源可关注左侧微信公众号获取!