bookdao.java

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

JAVA
360
字号
   //以图书名字为条件的查询
     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 selectBooksortNumbers(BookForm form) {
                        BookForm bookForm=null;
                        String sql = "select * from tb_book where sortNumber='"+form.getSortNumber()+"'";
                        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 + -
显示快捷键?