图书管理系统。发一下这个系统的要求,如果不看要求,好像也不懂我的代码到底是干嘛!
石家庄铁道大学图书管理系统
1、项目需求:
图书馆管理系统,能进图书管理系统软件图书管理系统软件行图书馆管理系统能实测国民经济和企业的各种运行情况;利用过去的数据预测未来;从企业全局出发辅助企业进行管理决策;利用信息控制企业的行为;帮助企业实现其规划目标。
2.系统要求与功能设计
2.1 页面要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;
(2)网站页面整体风格统一;
(3)首页(登录页)要求实现不同用户登录后,进入的功能页不相同。
(4)读者功能页:有浏览图书信息、查询图书信息、借阅图书,浏览催还书目、归还图书五个功能模块。
(5)管理员功能页:有添加读者信息、添加新书信息、打印催还书目信息三个模块。
2.2功能要求:
(1)浏览图书信息:读者登录后以列表形式可以查看所有图书基本信息,包括唯一编号、书名、作者名、出版社名称信息、可借阅数量;
(2)查询图书信息:可以按照书名或作者名进行模糊检索,以列表形式查看符合条件的图书信息。
(3)借阅图书功能:读者选择查询图书相应信息,跳转到书目的详细信息界面,当可借阅数量大于零,点击借阅按钮,提示用户借阅成功,并显示归还日期(三个月),否则提示用户该书可借阅数量为0,无法借阅。
(4)浏览催还书目:读者查看个人超期的图书列表信息。
(5)归还图书功能:读者可以查看个人借阅的所有书目列表信息,选择其中一项,则跳转到书目的详细信息界面,点击归还按钮,提示用户还书成功,如果该书超期,以一天0.1元计算罚金,提示用户需要缴纳罚金。
(6)添加读者基本信息:管理员可以添加读者基本信息,读者基本信息包括学号(八位数字组成,例如20180052)、读者姓名、读者性别、所在学院组成;
(7)添加新书基本信息:管理员可以添加新书基本信息,新书基本信息包括唯一编号、书名、作者名、出版社名称,可借阅数量;
(8)打印催还书目功能:显示所有用户的超期图书信息;
(9)登陆功能:管理员、读者登陆后可以看到不同的功能页面,读者登陆后只能看到自己的相关信息,不同读者登陆后无法查看其他人的信息。(要求至少创建五个读者用户演示选课过程)
3数据库设计:
要求实现图书基本信息表、借阅基本信息表、催还基本信息表、读者基本信息表。
4、WEB发布:
要求可以实现在浏览器直接访问系统。
哈哈!!!
今天就发一下dao层和javabean的数据的代码吧
链接数据库代码
package dao; import java.sql.*; public class DBUtil { //eshop为数据库名称,db_user为数据库用户名db_password为数据库密码 public static String db_url = "jdbc:mysql://localhost:3306/library?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT"; public static String db_user = "root"; public static String db_password = "root1"; public static Connection getConn() { Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver"); conn = DriverManager.getConnection(db_url, db_user, db_password); System.out.println("连接成功"); } catch (Exception e) { System.out.println("连接失败"); e.printStackTrace(); } return conn; } public static void close(Statement state, Connection conn) { if(state!=null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn!=null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close(ResultSet rs, Statement state, Connection conn) { if(rs!=null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if(state!=null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if(conn!=null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
package dao; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date; import javax.servlet.http.HttpSession; import entity.School; public class SchoolDaoImpl implements SchoolDao{ Connection conn=(Connection)DBUtil.getConn(); public boolean Stuadd(String stuID,String stupassword,String stuname,String stusex,String college) { //youyong boolean flag=false; PreparedStatement ps=null; try { //String sql="insert into school values('"+school.getclassname()+"','"+school.getclassteacher()+"','"+school.getclassplace()+"')"; ps=conn.prepareStatement("insert into student(stuID,stupassword,stuname,stusex,college)"+"values(?,?,?,?,?)"); ps.setString(1,stuID); ps.setString(2,stupassword); ps.setString(3,stuname); ps.setString(4,stusex); ps.setString(5, college); int i=ps.executeUpdate(); ps.close(); conn.close(); if(i>0) { flag = true;System.out.println("添加成功"); } }catch(SQLException e) { e.printStackTrace(); } return flag; } public boolean Bookadd(String bookID,String bookname,String author,String banname,String booknum) { //youyong boolean flag=false; PreparedStatement ps=null; try { //String sql="insert into school values('"+school.getclassname()+"','"+school.getclassteacher()+"','"+school.getclassplace()+"')"; ps=conn.prepareStatement("insert into book(bookID,bookname,author,banname,booknum)"+"values (?,?,?,?,?)"); ps.setString(1,bookID); ps.setString(2,bookname); ps.setString(3,author); ps.setString(4,banname); ps.setString(5,booknum); int i=ps.executeUpdate(); ps.close(); conn.close(); if(i>0) { flag = true; System.out.println("添加成功"); } }catch(SQLException e) { e.printStackTrace(); } return flag; } /*public boolean classadd(String teacherID,String teachername,String classID,String classname,String classnum) { boolean flag=false; PreparedStatement ps=null; try { //String sql="insert into school values('"+school.getclassname()+"','"+school.getclassteacher()+"','"+school.getclassplace()+"')"; ps=conn.prepareStatement("insert into class(teacherID,teachername,classID,classname,classnum)"+"values (?,?,?,?,?)"); ps.setString(1,teacherID); ps.setString(2,teachername); ps.setString(3,classID); ps.setString(4,classname); ps.setString(5,classnum); int i=ps.executeUpdate(); ps.close(); conn.close(); if(i>0) { flag = true;System.out.println("添加成功"); } }catch(SQLException e) { e.printStackTrace(); } return flag; } */ /*public List<School>showclass(){ List<School> list = new ArrayList<School>(); try { System.out.println(1); String sql="select * from class"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); System.out.println(2); while(rs.next()) { School school=new School(); school.setTeacherID(rs.getString("teacherID")); school.setClassID(rs.getString("classID")); school.setClassname(rs.getString("classname")); school.setClassnum(rs.getString("classnum")); school.setTeachername(rs.getString("teachername")); school.setClassnow(rs.getInt("classnow")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; }*/ public List<School>bookshow(){//youyong List<School> list = new ArrayList<School>(); try { String sql="select * from book"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("Bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); school.setBooknow(rs.getInt("booknow")); school.setBooknum(rs.getString("booknum")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public String showstuname(String stuID){//youyong String password=null; try { String sql="select * from student where stuID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1,stuID); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); school.setStupassword(rs.getString("stupassword")); password=school.getStupassword(); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return password; } public List<School>stushow(String stuID){//youyong List<School> list = new ArrayList<School>(); try { String sql="select * from student where stuID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1,stuID); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); school.setStuID(rs.getString("stuID")); System.out.println(stuID); school.setStupassword(rs.getString("stupassword")); school.setStuname(rs.getString("stuname")); school.setStusex(rs.getString("stusex")); school.setCollege(rs.getString("college")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public List<School> selecebookname(String xinxi) { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { System.out.println(1); String sql="select * from book where bookname like ?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, "%"+xinxi+"%"); ResultSet rs = pstmt.executeQuery(); System.out.println(2); while(rs.next()) { School school=new School(); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); school.setBooknum(rs.getString("booknum")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public List<School> selectbook(String xinxi) { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { System.out.println(1); String sql="select * from book where author like ?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, "%"+xinxi+"%"); ResultSet rs = pstmt.executeQuery(); System.out.println(2); while(rs.next()) { School school=new School(); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); school.setBooknum(rs.getString("booknum")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public List<School> bookshow1() { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { String sql="select * from book"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); school.setBooknum(rs.getString("booknum")); school.setBooknow(rs.getInt("booknow")); int now=school.getBooknow(); int num = Integer.parseInt(school.getBooknum()); if(now<num) { school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("Bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); school.setBooknow(rs.getInt("booknow")); school.setBooknum(rs.getString("booknum")); list.add(school);} } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public boolean bookadd(School school,String timenow,String timenext) { // TODO 自动生成的方法存根 boolean flag=false; PreparedStatement ps=null; try { //String sql="insert into school values('"+school.getclassname()+"','"+school.getclassteacher()+"','"+school.getclassplace()+"')"; ps=conn.prepareStatement("insert into studentbook(stuID,stuname,stusex,college,bookID,bookname,author,banname,timenow,timenext)"+"values(?,?,?,?,?,?,?,?,?,?)"); ps.setString(1,school.getStuID()); ps.setString(2,school.getStuname()); ps.setString(3,school.getStusex()); ps.setString(4,school.getCollege()); ps.setString(5,school.getBookID() ); ps.setString(6,school.getBookname() ); ps.setString(7,school.getAuthor() ); ps.setString(8,school.getBanname() ); ps.setString(9,timenow); ps.setString(10,timenext); int i=ps.executeUpdate(); ps.close(); conn.close(); if(i>0) { flag = true;System.out.println("添加成功"); } }catch(SQLException e) { e.printStackTrace(); } return flag; } public boolean update(String booknum,String bookID) { // TODO 自动生成的方法存根 boolean flag=false; try { String sql="update book set booknum=? where bookID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1,booknum); System.out.println(booknum+'2'); pstmt.setString(2,bookID); int i = pstmt.executeUpdate(); pstmt.close(); conn.close(); if(i>0) {flag = true;System.out.println("修改成功!!!");} }catch(SQLException e) { e.printStackTrace(); } return flag; } public List<School> bookshow2(String stuID) { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { String sql="select * from studentbook where stuID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, stuID); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); school.setStuID("stuID"); school.setStuname("stuname"); school.setStusex("stusex"); school.setCollege("college"); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("Bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); list.add(school); } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public boolean delete(String bookID) { // TODO 自动生成的方法存根 boolean flag=false; try { String sql="delete from studentbook where bookID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, bookID); int i = pstmt.executeUpdate(); pstmt.close(); conn.close(); if(i>0) {flag = true;System.out.println("修改成功!!!");} }catch(SQLException e) { e.printStackTrace(); } return flag; } public List<School> bookreturnshow(String stuID) throws ParseException { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { String sql="select * from studentbook where stuID=?"; PreparedStatement pstmt = conn.prepareStatement(sql); pstmt.setString(1, stuID); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); String timenext=rs.getString("timenext"); Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String timenow=formatter.format(date); java.util.Date date1=formatter.parse(timenow); System.out.println(timenow); java.util.Date date2=formatter.parse(timenext); if(date1.after(date2)) { school.setStuID("stuID"); school.setStuname("stuname"); school.setStusex("stusex"); school.setCollege("college"); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("Bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); list.add(school);} } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } public List<School> allbookreturnshow() throws ParseException { // TODO 自动生成的方法存根 List<School> list = new ArrayList<School>(); try { String sql="select * from studentbook"; PreparedStatement pstmt = conn.prepareStatement(sql); ResultSet rs = pstmt.executeQuery(); while(rs.next()) { School school=new School(); String timenext=rs.getString("timenext"); Date date = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String timenow=formatter.format(date); java.util.Date date1=formatter.parse(timenow); System.out.println(timenow); java.util.Date date2=formatter.parse(timenext); if(date1.after(date2)) { school.setStuID("stuID"); school.setStuname("stuname"); school.setStusex("stusex"); school.setCollege("college"); school.setBookID(rs.getString("bookID")); school.setBookname(rs.getString("Bookname")); school.setAuthor(rs.getString("author")); school.setBanname(rs.getString("banname")); list.add(school);} } rs.close(); pstmt.close(); conn.close(); }catch(SQLException e) { e.printStackTrace(); } return list; } }
package entity; public class School { private String prefession; private String password; private String username; private String stuID; private String stupassword; private String stuname; private String stusex; public String getPrefession() { return prefession; } public void setPrefession(String prefession) { this.prefession = prefession; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getStupassword() { return stupassword; } public void setStupassword(String stupassword) { this.stupassword = stupassword; } private String college; private String bookID; private String bookname; private String author; private String banname; private String booknum; private int booknow; public int getBooknow() { return booknow; } public void setBooknow(int booknow) { this.booknow = booknow; } public String getStuID() { return stuID; } public void setStuID(String stuID) { this.stuID = stuID; } public String getStuname() { return stuname; } public void setStuname(String stuname) { this.stuname = stuname; } public String getStusex() { return stusex; } public void setStusex(String stusex) { this.stusex = stusex; } public String getCollege() { return college; } public void setCollege(String college) { this.college = college; } public String getBookID() { return bookID; } public void setBookID(String bookID) { this.bookID = bookID; } public String getBookname() { return bookname; } public void setBookname(String bookname) { this.bookname = bookname; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getBanname() { return banname; } public void setBanname(String banname) { this.banname = banname; } public String getBooknum() { return booknum; } public void setBooknum(String booknum) { this.booknum = booknum; } }
之所以分开发这些代码,是因为我写的很繁琐很多,如果一次发出去,会特别多,特别长!所以就把它们分开发。