borrowbookdao.java

来自「图书管理系统。JSP+Struts(MVC框架)sql2000数据库」· Java 代码 · 共 276 行

JAVA
276
字号
package com.dao;

import java.sql.*;
import org.apache.xml.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import com.tool.JDBCConnection;
import com.actionForm.BorrowBookForm;


public class BorrowBookDao {
     private JDBCConnection con=null;

    public BorrowBookDao() {
     con=new JDBCConnection();
     this.con.createConnection();
    }

/******************增加图书借阅信息*************************************/
    public boolean insertBorrowBook(BorrowBookForm bookForm) {
        try{
            String sql = "insert into tb_borrowBook values('" +
                         bookForm.getBooklink() + "','" + bookForm.getBookName()
                         + "','" + bookForm.getBookAuthor() + "','"+bookForm.getBookPunbilc()+"','" +
                         bookForm.getBookPrice() + "','" + bookForm.getLendPrice() + "','" +
                         bookForm.getReaderCard() + "','" +
                         bookForm.getStartTime()
                         + "','" + bookForm.getOverTime() + "','" +
                         bookForm.getLend() + "','" + bookForm.getOperation() +
                         "')";
            con.executeQuery(sql);
            con.closeConneciton();
            return true;
        }catch(Exception e){
        return false;
        }
     }

/************************删除*****************************************/
     public boolean deleteBorrowBook(BorrowBookForm bookForm){
         try{
             String sql = "delete from tb_borrowBook where id='"+bookForm.getId()+"'";
             con.executeUpdata(sql);
             System.out.println("删除成功!!!");
             con.closeConneciton();
             return true;
         }catch(Exception e){
         System.out.println("删除失败!!!");
         return false;
         }
    }

/******************************续借*****************************************/
     public boolean UpdateBorrowBook(BorrowBookForm bookForm){
         try{
             String sql = "update tb_borrowBook set booklink='"+bookForm.getBooklink()+"',bookName='" +bookForm.getBookName()
                          + "',bookAuthor='" +bookForm.getBookAuthor() + "',bookPunbilc='"
                          +bookForm.getBookPunbilc() + "',bookPirce='" +bookForm.getBookPrice()
                          + "',lendPrice='" +bookForm.getLendPrice() + "',startTime='" +bookForm.getStartTime()
                          + "',overTime='" +bookForm.getOverTime() + "',lend='"
                          +bookForm.getLend() + "',operation='" +bookForm.getOperation()
                          + "', where  readerCard='" + bookForm.getReaderCard() +"'";
             con.executeUpdata(sql);
             System.out.println("续借成功!!!");
             con.closeConneciton();
             return true;
         }catch(Exception e){
         System.out.println("续借失败!!!");
         return false;
         }
   }

/*********************************查询******************************************/
   public BorrowBookForm selectBorrowBookGoOn(BorrowBookForm bookForm1) {
       BorrowBookForm bookForm=null;
      String sql = "select * from tb_borrowBook where readerCard='"+bookForm1.getReaderCard()+"'";
      ResultSet rs = con.executeQuery(sql);
        try {
         while(rs.next()){
             bookForm=new BorrowBookForm();
         bookForm.setId(Integer.valueOf(rs.getString("id")));
         bookForm.setBooklink(rs.getInt("booklink"));
         bookForm.setBookName(rs.getString("bookName"));
         bookForm.setBookAuthor(rs.getString("bookAuthor"));
         bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
         bookForm.setBookPrice(rs.getFloat("bookPrice"));
         bookForm.setLendPrice(rs.getFloat("lendPrice"));
         bookForm.setReaderCard(rs.getString("readerCard"));
         bookForm.setStartTime(rs.getString("startTime"));
         bookForm.setOverTime(rs.getString("overTime"));
         bookForm.setLend(rs.getString("lend"));
         bookForm.setOperation(rs.getString("operation"));
         }
        } catch (Exception ex) {}
        return bookForm;
    }
   //判断未还书情况查询
    public List selectBorrowBookGoOne(BorrowBookForm bookForm1) {
       BorrowBookForm bookForm=null;
        List list = new ArrayList();
      String sql = "select * from tb_borrowBook where lend='0' and readerCard='"+bookForm1.getReaderCard()+"'";
      ResultSet rs = con.executeQuery(sql);
        try {
         while(rs.next()){
             bookForm=new BorrowBookForm();
         bookForm.setId(Integer.valueOf(rs.getString("id")));
         bookForm.setBooklink(rs.getInt("booklink"));
         bookForm.setBookName(rs.getString("bookName"));
         bookForm.setBookAuthor(rs.getString("bookAuthor"));
         bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
         bookForm.setBookPrice(rs.getFloat("bookPrice"));
         bookForm.setLendPrice(rs.getFloat("lendPrice"));
         bookForm.setReaderCard(rs.getString("readerCard"));
         bookForm.setStartTime(rs.getString("startTime"));
         bookForm.setOverTime(rs.getString("overTime"));
         bookForm.setLend(rs.getString("lend"));
         bookForm.setOperation(rs.getString("operation"));
         list.add(bookForm);
         }
        } catch (Exception ex) {}

        return list;
    }

    //以图书名为条件的查询
    public BorrowBookForm selectBorrowBookName(BorrowBookForm bookForm) {
       String sql = "select * from tb_borrowBook where bookName='"+bookForm.getBookName()+"'";
       ResultSet rs = con.executeQuery(sql);
         try {
          while(rs.next()){
              bookForm=new BorrowBookForm();
          bookForm.setId(Integer.valueOf(rs.getString("id")));
          bookForm.setBooklink(rs.getInt("booklink"));
          bookForm.setBookName(rs.getString("bookName"));
          bookForm.setBookAuthor(rs.getString("bookAuthor"));
          bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
          bookForm.setBookPrice(rs.getFloat("bookPrice"));
          bookForm.setLendPrice(rs.getFloat("lendPrice"));
          bookForm.setReaderCard(rs.getString("readerCard"));
          bookForm.setStartTime(rs.getString("startTime"));
          bookForm.setOverTime(rs.getString("overTime"));
          bookForm.setLend(rs.getString("lend"));
          bookForm.setOperation(rs.getString("operation"));
          }
         } catch (Exception ex) {}
         return bookForm;
    }

    //查询该书已经被借用数量
    public List selectBorrowBookNumber(BorrowBookForm bookForm1) {
        List list = new ArrayList();
      String sql = "select * from tb_borrowBook where lend='0' and booklink='"+bookForm1.getBooklink()+"'";
        BorrowBookForm bookForm=new BorrowBookForm();
      ResultSet rs = con.executeQuery(sql);
        try {
         while(rs.next()){
         bookForm=new BorrowBookForm();
         bookForm.setId(Integer.valueOf(rs.getString("id")));
         bookForm.setBooklink(rs.getInt("booklink"));
         bookForm.setBookName(rs.getString("bookName"));
         bookForm.setBookAuthor(rs.getString("bookAuthor"));
         bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
         bookForm.setBookPrice(rs.getFloat("bookPrice"));
         bookForm.setLendPrice(rs.getFloat("lendPrice"));
         bookForm.setReaderCard(rs.getString("readerCard"));
         bookForm.setStartTime(rs.getString("startTime"));
         bookForm.setOverTime(rs.getString("overTime"));
         bookForm.setLend(rs.getString("lend"));
         bookForm.setOperation(rs.getString("operation"));
         list.add(bookForm);
         }
        } catch (Exception ex) {
        }
        return list;
    }

    //全部查询
    public List selectBorrowBook() {
      List list = new ArrayList();
      BorrowBookForm bookForm=null;
      String sql="select * from tb_borrowBook";
      ResultSet rs=con.executeQuery(sql);
      try {
          while(rs.next()){
         bookForm=new BorrowBookForm();
         bookForm.setId(Integer.valueOf(rs.getString("id")));
         bookForm.setBooklink(rs.getInt("booklink"));
         bookForm.setBookName(rs.getString("bookName"));
         bookForm.setBookAuthor(rs.getString("bookAuthor"));
         bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
         bookForm.setBookPrice(rs.getFloat("bookPrice"));
         bookForm.setLendPrice(rs.getFloat("lendPrice"));
         bookForm.setReaderCard(rs.getString("readerCard"));
         bookForm.setStartTime(rs.getString("startTime"));
         bookForm.setOverTime(rs.getString("overTime"));
         bookForm.setLend(rs.getString("lend"));
         bookForm.setOperation(rs.getString("operation"));
         list.add(bookForm);
         }
      } catch (Exception ex) {}
      return list;
    }

   public List selectBorrowBook(int number) {
       List list = new ArrayList();
     BorrowBookForm bookForm=null;
     String sql="select * from tb_borrowBook order by id";
     ResultSet rs=con.executeQuery(sql);
     try{
        while(rs.next()){
        bookForm=new BorrowBookForm();
         bookForm.setId(Integer.valueOf(rs.getString("id")));
         bookForm.setBooklink(rs.getInt("booklink"));
         bookForm.setBookName(rs.getString("bookName"));
         bookForm.setBookAuthor(rs.getString("bookAuthor"));
         bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
         bookForm.setBookPrice(rs.getFloat("bookPrice"));
         bookForm.setLendPrice(rs.getFloat("lendPrice"));
         bookForm.setReaderCard(rs.getString("readerCard"));
         bookForm.setStartTime(rs.getString("startTime"));
         bookForm.setOverTime(rs.getString("overTime"));
         bookForm.setLend(rs.getString("lend"));
         bookForm.setOperation(rs.getString("operation"));
         list.add(bookForm);
        }
     }catch(Exception e){}
     con.closeConneciton();
     number = list.size();
     if (number % 13== 0) {number = number / 13;}
     else {number = number / 13 + 1;}
       return list;
    }
/***********************************************************************/
    public boolean UpdateBorrowBooklend(BorrowBookForm bookForm) {
            try {
                String sql = "update tb_borrowBook set lend='"
                             + bookForm.getLend() + "'  where  readerCard='" + bookForm.getReaderCard() +
                             "'";
                con.executeUpdata(sql);
                System.out.println("归还成功!!!");
                con.closeConneciton();
                return true;
            } catch (Exception e) {
                System.out.println("归还失败!!!");
                return false;
            }
    }

    public BorrowBookForm selectBorrowBookGID(BorrowBookForm bookForm1) {
       BorrowBookForm bookForm=null;
           String sql = "select * from tb_borrowBook where id='"+bookForm1.getId()+"'";
           ResultSet rs = con.executeQuery(sql);
           try {
               while (rs.next()) {
                   bookForm=new BorrowBookForm();
                   bookForm.setId(Integer.valueOf(rs.getString("id")));
                   bookForm.setBooklink(rs.getInt("booklink"));
                   bookForm.setBookName(rs.getString("bookName"));
                   bookForm.setBookAuthor(rs.getString("bookAuthor"));
                   bookForm.setBookPunbilc(rs.getString("bookPunbilc"));
                   bookForm.setBookPrice(rs.getFloat("bookPrice"));
                   bookForm.setLendPrice(rs.getFloat("lendPrice"));
                   bookForm.setReaderCard(rs.getString("readerCard"));
                   bookForm.setStartTime(rs.getString("startTime"));
                   bookForm.setOverTime(rs.getString("overTime"));
                   bookForm.setLend(rs.getString("lend"));
                   bookForm.setOperation(rs.getString("operation"));
               }
           } catch (Exception ex) {}
           return bookForm;
       }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?