图书管理系统(源码)

  • o6_116495
    了解作者
  • 3.6MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 21:17
    上传日期
图书管理系统源码 包含数据库代码 可运行
图书管理系统(源码).zip
内容介绍
package com.wsy.dao; import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import com.wsy.model.Back; import com.wsy.model.BookInfo; import com.wsy.model.BookType; import com.wsy.model.Borrow; import com.wsy.model.Operater; import com.wsy.model.Order; import com.wsy.model.OrderAndBookInfo; import com.wsy.model.Reader; import com.wsy.model.user; public class Dao { protected static String dbClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; protected static String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;" + "DatabaseName=db_library;SelectMethod=Cursor"; protected static String dbUser = "sa"; protected static String dbPwd = ""; protected static String second = null; private static Connection conn = null; private Dao() { try { if (conn == null) { Class.forName(dbClassName).newInstance(); conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd); } else return; } catch (Exception ee) { ee.printStackTrace(); } } private static ResultSet executeQuery(String sql) { try { if(conn==null) new Dao(); return conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); return null; } finally { } } private static int executeUpdate(String sql) { try { if(conn==null) new Dao(); return conn.createStatement().executeUpdate(sql); } catch (SQLException e) { System.out.println(e.getMessage()); //if(e.getMessage().equals("[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE 语句与 COLUMN REFERENCE 约束 'FK_TB_BORRO_REFERENCE_TB_BOOKI' 冲突。该冲突发生于数据库 'db_library',表 'tb_borrow', column 'bookISBN'。")) return -1; } finally { } } public static void close() { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); }finally{ conn = null; } } /* * 管理员登录方法 */ public static Operater check(String name, String password) { int i = 0; Operater operater=new Operater(); String sql = "select * from tb_operator where name='" + name + "' and password='" + password + "'and admin=1"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { String names = rs.getString(1); operater.setId(rs.getString("id")); operater.setName(rs.getString("name")); operater.setGrade(rs.getString("admin")); operater.setPassword(rs.getString("password")); if (names != null) { i = 1; } } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return operater; } /* * 查询类别方法 */ public static List selectBookCategory() { List list=new ArrayList(); String sql = "select * from tb_bookType"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { BookType bookType=new BookType(); bookType.setId(rs.getString("id")); bookType.setTypeName(rs.getString("typeName")); bookType.setDays(rs.getString("days")); bookType.setFk(rs.getString("fk")); list.add(bookType); } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return list; } public static List selectBookCategory(String bookType) { List list=new ArrayList(); String sql = "select days from tb_bookType where typeName='"+bookType+"'"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { BookType type=new BookType(); type.setDays(rs.getString("days")); list.add(type); } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return list; } /* * 图书类别表相关操作 * */ public static int InsertBookType(String bookTypeName,String days,Double fk){ int i=0; try{ String sql="insert into tb_bookType(typeName,days,fk) values('"+bookTypeName+"','"+days+"',"+fk+")"; i=Dao.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); } return i; } public static int UpdatebookType(String id,String typeName,String days,String fk){ int i=0; try{ String sql="update tb_bookType set typeName='"+typeName+"',days='"+days+"',fk='"+fk+"' where id='"+id+"'"; //System.out.println(sql); i=Dao.executeUpdate(sql); }catch(Exception e){ e.printStackTrace(); } Dao.close(); return i; } // public static int DelbookType(String id){ // int i=0; // try{ // String sql="delete from tb_bookType where id='"+id+"'"; // //System.out.println(sql); // i=Dao.executeUpdate(sql); // }catch(Exception e){ // e.printStackTrace(); // } // Dao.close(); // return i; // } public static List selectBookTypeFk(String bookType) {//取每种书超过规定时间罚款金额 List list=new ArrayList(); String sql = "select * from tb_bookType where typeName='"+bookType+"'"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { BookType type=new BookType(); type.setFk(rs.getString("fk")); type.setDays(rs.getString("days")); list.add(type); } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return list; } /* * 图书信息表相关操作 */ /* * 插入图书信息方法 */ public static int Insertbook(String ISBN,String typeId,String bookname,String writer,String translator,String publisher,Date date,Double price){ int i=0; try{ String sql="insert into tb_bookInfo(ISBN,typeId,bookname,writer,translator,publisher,date,price) values('"+ISBN+"','"+typeId+"','"+bookname+"','"+writer+"','"+translator+"','"+publisher+"','"+date+"',"+price+")"; //System.out.println(sql); i=Dao.executeUpdate(sql); }catch(Exception e){ System.out.println(e.getMessage()); } Dao.close(); return i; } /* * 查询图书相关信息 * */ public static List selectBookInfo() { List list=new ArrayList(); String sql = "select * from tb_bookInfo"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { BookInfo bookinfo=new BookInfo(); bookinfo.setISBN(rs.getString("ISBN")); bookinfo.setTypeid(rs.getString("typeid")); bookinfo.setBookname(rs.getString("bookname")); bookinfo.setWriter(rs.getString("writer")); bookinfo.setTranslator(rs.getString("translator")); bookinfo.setPublisher(rs.getString("publisher")); bookinfo.setDate(rs.getDate("date")); bookinfo.setPrice(rs.getDouble("price")); list.add(bookinfo); } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return list; } public static List selectBookInfo(String ISBN) { List list=new ArrayList(); String sql = "select * from tb_bookInfo where ISBN='"+ISBN+"'"; ResultSet rs = Dao.executeQuery(sql); try { while (rs.next()) { BookInfo bookinfo=new BookInfo(); bookinfo.setISBN(rs.getString("ISBN")); bookinfo.setTypeid(rs.getString("typeid")); bookinfo.setBookname(rs.getString("bookname")); bookinfo.setWriter(rs.getString("writer")); bookinfo.setTranslator(rs.getString("translator")); bookinfo.setPublisher(rs.getString("publisher")); bookinfo.setDate(rs.getDate("date")); bookinfo.setPrice(rs.getDouble("price")); list.add(bookinfo); } } catch (Exception e) { e.printStackTrace(); } Dao.close(); return list; } /* * 修改图书信息方法 */ public static int Updatebook(String ISBN,String typeId,String bookname,String writer,String translator,String publisher,Date date,Double price){ int i=0; try{ String sql="update tb_bookInfo set ISBN='"+ISBN+"',typeId='"+typeId+"',bookname='"+bookname+"',writer='"+writer+"',translator='"+translator+"',publisher='"+publisher+"',date='"+date+"',price="+price+" where ISBN='"+ISBN+"
评论
    相关推荐
    • 数据库
      数据库
    • 数据库
      数据库 信使
    • 数据库
      数据库
    • 数据库数据库
      数据库数据库
    • 数据库
      数据库
    • 数据库
      数据库
    • 数据库 热备
      数据库自动切换,A>B>C>>A>B>C... 如果加上数据库复制,就是完整的数据库热备了。 数据库复制请参考数据库文档
    • 数据库数据库数据库
      数据库课件 东北大学 软件学院 数据库课件 东北大学 软件学院
    • 数据库设计
      本书是一本介绍数据库设计技术的著作,数据库设计是开发一个好的数据库应用系统的基础,本书运用大量实例对数据库设计过程中所涉及到的技术和知识进行了详细的介绍。本书的内容包括:数据库的基本原理、常用的数据库...
    • 数据库
      数据库