bookdao.java~1~

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

JAVA~1~
331
字号
package com.dao;

import java.sql.SQLException;
import java.sql.*;
import java.lang.String;
import org.apache.xml.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.tool.JDBCConnection;
import com.actionForm.BookForm;
import java.util.*;
import java.sql.ResultSet;
import com.tool.DealwithString;
import java.lang.String;

public class BookDao {
    private JDBCConnection con=null;

    public BookDao(){
       con=new JDBCConnection();
       this.con.createConnection();
    }
////////////////////////////////////////////////////////
    //添加图书信息的方法
   public boolean insertBook(BookForm bookForm) {
       try{
           String sql = "insert into tb_book values('" + bookForm.getBookNumber() +
                        "','" + bookForm.getLineNumber()
                        + "','" + bookForm.getBookName() + "','" +
                        bookForm.getAuthor() + "','" + bookForm.getPublish()
                        + "','" + bookForm.getPublishNumber() + "','" +
                        bookForm.getSortNumber()
                        + "','" + bookForm.getInPirce() + "','" +
                        bookForm.getSinglePirce() + "','" + bookForm.getBookSum()
                        + "','" + bookForm.getMan() + "','" +
                        bookForm.getCreatime() + "')";
           con.executeUpdata(sql);
           con.closeConneciton();
           return true;
       }catch(Exception e){
       return false;
       }
    }

/*************************************************************/
    //删除图书
    public boolean deleteBook(BookForm bookForm) {
        try{
            String sql = "delete from tb_book where bookNumber='" + bookForm.getBookNumber() +"'";
            con.executeUpdata(sql);
            con.closeConneciton();
            return true;
        }catch(Exception e){
            return false;}

    }
/********************************************************************/
    //以图书编号修改图书全部信息
      public boolean UpdateBook(BookForm  bookForm){
          //TBBookActionForm bookForm=null;
          try{
              String sql = "update tb_book set lineNumber='" +
                           bookForm.getLineNumber() + "',bookName='"+bookForm.getBookName()+"',author='" +
                           bookForm.getAuthor() + "',publish='" +
                           bookForm.getPublish() + "',publishNumber='" +
                           bookForm.getPublishNumber() + "',sortNumber='" +
                           bookForm.getSortNumber() + "',inPirce='" +
                           bookForm.getInPirce() + "',singlePirce='" +
                           bookForm.getSinglePirce() + "',bookSum='" +
                           bookForm.getBookSum() + "',man='" + bookForm.getMan() +
                           "',creatime='" + bookForm.getCreatime() +
                           "' where bookNumber='" + bookForm.getBookNumber() + "'";
              con.executeUpdata(sql);
              con.closeConneciton();
          }catch(Exception e){
          System.out.println("图书信息修改失败!!!");
          }
          return true;
  }
  /*****************************************************************************/
  //以图书编号为条件修改图书数量
          public boolean addBook(BookForm form) {
             try{
                 String sql = "update tb_book set bookSum='" + form.getBookSum()
                              + "' where bookNumber='" + form.getBookNumber() +
                              "'";
                 con.executeUpdata(sql);
                 con.closeConneciton();
                 System.out.println("updateBook is successful");
                 return true;
             }catch(Exception e){
                 return false;
             }
         }
/*************************************************************************/
         //以图书条形码为条件修改图书数量
         public boolean addOneBook(BookForm form) {
            try{
                String sql = "update tb_book set bookSum='" + form.getBookSum()
                             + "' where lineNumber='" + form.getLineNumber() +
                             "'";
                con.executeUpdata(sql);
                con.closeConneciton();
                System.out.println("updateOneBook is successful");
                return true;
            }catch(Exception e){
                return false;
            }
        }

/*//**********************************************************/
   //查询出多少条纪录
   public int selectBooks(){
       List list = new ArrayList();
       BookForm bookForm=null;
       String sql=("select * from tb_book order by id");
       ResultSet rs=con.executeQuery(sql);
        try{
          bookForm=new BookForm();
          bookForm.setId(Integer.valueOf(rs.getString("id")));
          bookForm.setBookNumber(rs.getString("bookNumber"));
          bookForm.setLineNumber(rs.getString("lineNumber"));
          bookForm.setBookName(rs.getString("bookName"));
          bookForm.setAuthor(rs.getString("author"));
          bookForm.setPublish(rs.getString("publish"));
          bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
          bookForm.setSortNumber(rs.getString("sortNumber"));
          bookForm.setInPirce(rs.getFloat("inPirce"));
          bookForm.setSinglePirce(rs.getFloat("singlePirce"));
          bookForm.setBookSum(rs.getInt("bookSum"));
          bookForm.setMan(rs.getString("man"));
          bookForm.setCreatime(rs.getString("creatime"));
          list.add(bookForm);
        }catch(Exception e){}
        int number=list.size();
        if (number % 13 == 0) {
            number = number / 13;
        } else {
            number = number / 13 + 1;
        }
       con.closeConneciton();
       return number;
   }

   //全部查询
   public List selectBooks(int number){
       List list = new ArrayList();
       BookForm bookForm=null;
       String sql=("select * from tb_book order by id");
       ResultSet rs=con.executeQuery(sql);
       try{
          while(rs.next()){
          bookForm=new BookForm();
          bookForm.setId(Integer.valueOf(rs.getString("id")));
          bookForm.setBookNumber(rs.getString("bookNumber"));
          bookForm.setLineNumber(rs.getString("lineNumber"));
          bookForm.setBookName(rs.getString("bookName"));
          bookForm.setAuthor(rs.getString("author"));
          bookForm.setPublish(rs.getString("publish"));
          bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
          bookForm.setSortNumber(rs.getString("sortNumber"));
          bookForm.setInPirce(rs.getFloat("inPirce"));
          bookForm.setSinglePirce(rs.getFloat("singlePirce"));
          bookForm.setBookSum(rs.getInt("bookSum"));
          bookForm.setMan(rs.getString("man"));
          bookForm.setCreatime(rs.getString("creatime"));
          list.add(bookForm);
          }
          number=list.size();
          if (number*13 == 0) {
           number = number*13;
           } else {
           number = number*13 + 1;
           }
       }catch(Exception e){}
       con.closeConneciton();
       return list;
   }

   //以图书名字为条件的查询
     public BookForm selectBookName(BookForm bookForm) {
          String sql = "select * from tb_book where bookName='"+bookForm.getBookName()+"'order by id";
          ResultSet rs = con.executeQuery(sql);
          try {
              while (rs.next()) {
                  bookForm=new BookForm();
                  bookForm.setId(Integer.valueOf(rs.getString("id")));
                  bookForm.setBookNumber(rs.getString("bookNumber"));
                  bookForm.setLineNumber(rs.getString("lineNumber"));
                  bookForm.setBookName(rs.getString("bookName"));
                  bookForm.setAuthor(rs.getString("author"));
                  bookForm.setPublish(rs.getString("publish"));
                  bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
                  bookForm.setSortNumber(rs.getString("sortNumber"));
                  bookForm.setInPirce(rs.getFloat("inPirce"));
                  bookForm.setSinglePirce(rs.getFloat("singlePirce"));
                  bookForm.setBookSum(rs.getInt("bookSum"));
                  bookForm.setMan(rs.getString("man"));
                  bookForm.setCreatime(rs.getString("creatime"));
              }
          } catch (SQLException ex) {
          }
          con.closeConneciton();
          return bookForm;
        }

        //以图书编号为条件查询图书信息的一组数据
              public BookForm selectBookNumbers(BookForm form) {
                         BookForm bookForm=null;
                         String sql = "select * from tb_book where bookNumber='"+form.getBookNumber()+"'";
                         ResultSet rs = con.executeQuery(sql);
                         try {
                            while (rs.next()) {
                              bookForm = new BookForm();
                              bookForm.setId(Integer.valueOf(rs.getString("id")));
                            bookForm.setBookNumber(rs.getString("bookNumber"));
                            bookForm.setLineNumber(rs.getString("lineNumber"));
                            bookForm.setBookName(rs.getString("bookName"));
                            bookForm.setAuthor(rs.getString("author"));
                            bookForm.setPublish(rs.getString("publish"));
                            bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
                            bookForm.setSortNumber(rs.getString("sortNumber"));
                            bookForm.setInPirce(rs.getFloat("inPirce"));
                            bookForm.setSinglePirce(rs.getFloat("singlePirce"));
                            bookForm.setBookSum(rs.getInt("bookSum"));
                            bookForm.setMan(rs.getString("man"));
                            bookForm.setCreatime(rs.getString("creatime"));
                              }
                              } catch (SQLException ex) {
                              }
                                   System.out.println(rs);
                              con.closeConneciton();
                                  return bookForm;
              }

        //以图书条形码为条件的查询
          public BookForm selectlineNumber(BookForm bookForm1) {
               String sql = "select * from tb_book where lineNumber='"+bookForm1.getLineNumber()+"'";
               BookForm bookForm=new BookForm();
               ResultSet rs = con.executeQuery(sql);
               try {
                   while (rs.next()) {
                       bookForm=new BookForm();
                       bookForm.setId(Integer.valueOf(rs.getString("id")));
                       bookForm.setBookNumber(rs.getString("bookNumber"));
                       bookForm.setLineNumber(rs.getString("lineNumber"));
                       bookForm.setBookName(rs.getString("bookName"));
                       bookForm.setAuthor(rs.getString("author"));
                       bookForm.setPublish(rs.getString("publish"));
                       bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
                       bookForm.setSortNumber(rs.getString("sortNumber"));
                       bookForm.setInPirce(rs.getFloat("inPirce"));
                       bookForm.setSinglePirce(rs.getFloat("singlePirce"));
                       bookForm.setBookSum(rs.getInt("bookSum"));
                       bookForm.setMan(rs.getString("man"));
                       bookForm.setCreatime(rs.getString("creatime"));
                   }
               } catch (SQLException ex) {
               }
               con.closeConneciton();
               return bookForm;
        }

        //全部查询
           public List selectBooksAll(){
               List list = new ArrayList();
               BookForm bookForm=null;
               String sql=("select * from tb_book order by id");
               ResultSet rs=con.executeQuery(sql);
               try{
                  while(rs.next()){
                  bookForm=new BookForm();
                  bookForm.setId(Integer.valueOf(rs.getString("id")));
                  bookForm.setBookNumber(rs.getString("bookNumber"));
                  bookForm.setLineNumber(rs.getString("lineNumber"));
                  bookForm.setBookName(rs.getString("bookName"));
                  bookForm.setAuthor(rs.getString("author"));
                  bookForm.setPublish(rs.getString("publish"));
                  bookForm.setPublishNumber(Integer.valueOf(rs.getString("publishNumber")));
                  bookForm.setSortNumber(rs.getString("sortNumber"));
                  bookForm.setInPirce(rs.getFloat("inPirce"));
                  bookForm.setSinglePirce(rs.getFloat("singlePirce"));
                  bookForm.setBookSum(rs.getInt("bookSum"));
                  bookForm.setMan(rs.getString("man"));
                  bookForm.setCreatime(rs.getString("creatime"));
                  list.add(bookForm);
                  }
               }catch(Exception e){}
               con.closeConneciton();
               return list;
   }
/******************************************************************************/
  //自动编号的方法
   public String selectMaxIdBook() {
       List list=new ArrayList();
      String book = null;
      BookForm bookForm = null;
      String sql="select * from tb_book where id=(select Max(id) from tb_book)";
      ResultSet rs=con.executeQuery(sql);
      try{
          while(rs.next()){
              bookForm = new BookForm();
              bookForm.setId(Integer.valueOf(rs.getString("id")));
              bookForm.setBookNumber(rs.getString("bookNumber"));
              bookForm.setLineNumber(rs.getString("lineNumber"));
              bookForm.setBookName(rs.getString("bookName"));
              bookForm.setAuthor(rs.getString("author"));
              bookForm.setPublish(rs.getString("publish"));
              bookForm.setPublishNumber(Integer.valueOf(rs.getString(
                      "publishNumber")));
              bookForm.setSortNumber(rs.getString("sortNumber"));
              bookForm.setInPirce(rs.getFloat("inPirce"));
              bookForm.setSinglePirce(rs.getFloat("singlePirce"));
              bookForm.setBookSum(rs.getInt("bookSum"));
              bookForm.setMan(rs.getString("man"));
              bookForm.setCreatime(rs.getString("creatime"));
              list.add(bookForm);
          }

      }catch(Exception e){e.printStackTrace();}
      if (bookForm != null) {
          book = bookForm.getBookNumber();
      }
      book = DealwithString.maxNumberString(book, "BOOK-", 5);
      return book;
    }


}

⌨️ 快捷键说明

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