⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 op_book.java

📁 很实用的JSP代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//         sqlStr = sqlStr + "and a.Bookclass='" +
//         classid + "' and (upper(a.bookname) like '%" +
//         keyword+ "%' or upper(a.content) like '%" +
//         keyword + "%')  order by a.Id desc";
//      } else {		//查询所有类
//        sqlStr = sqlStr + " and (upper(a.bookname) like '%" +
//        keyword+ "%' or upper(a.content) like '%" +
//        keyword + "%') order by a.Id desc";
//      }
//     } else {
      if (!classid.equals("")){
           sqlStr = sqlStr + " and a.Bookclass='" +
           classid + "' and (upper(a.bookname) like '%" +
           keyword+ "%' or upper(a.content) like '%" +
           keyword + "%') limit "+ pageSize * (page - 1)+","+
           pageSize;
//           (recordCount-pageSize * (page-1));
      } else {
            sqlStr = sqlStr + " and (upper(a.bookname) like '%" +
            keyword+ "%' or upper(a.content) like '%" +
            keyword + "%') limit "+(pageSize * (page - 1))+","+
            pageSize;
//            (recordCount-pageSize * (page-1));
            }
//                        }
  } else {//非查询,也非分类浏览
//         if (page == 1){
//              sqlStr = sqlStr + "  order by a.Id desc limit 0,"+pageSize;
//          } else {
              sqlStr = sqlStr + " order by a.Id desc limit "+(pageSize * (page - 1))+","+
              pageSize;
//              (recordCount-pageSize * (page-1));
//           }
        }
        try  {
              rs = db.stmt.executeQuery(sqlStr);
              booklist = new Vector(rscount);
              while (rs.next()){
                                book book = new book();
                                book.setId(rs.getLong("id"));
                                book.setBookName(rs.getString("bookname"));
                                book.setBookClass(rs.getInt("bookclass"));
                                book.setClassname(rs.getString("classname"));
                                book.setAuthor(rs.getString("author"));
                                book.setPublish(rs.getString("publish"));
                                book.setBookNo(rs.getString("bookno"));
                                book.setContent(rs.getString("content"));
                                book.setPrince(rs.getFloat("prince"));
                                book.setAmount(rs.getInt("amount"));
                                book.setLeav_number(rs.getInt("leav_number"));
                                book.setRegTime(rs.getString("regtime"));
                                book.setPicture(rs.getString("picture"));
                                booklist.addElement(book);
                        }
                        rs.close();
                        db.finalize();
                        return true;
                }catch (Exception e){
                        System.out.println(e.getMessage());
                        return false;
                }
        }
        /**
         * 完成图书添加
         * @return
         * @throws java.lang.Exception
         */
 public boolean insert() throws Exception {
  sqlStr = "insert into book (Bookname,Bookclass,Author,Publish,Bookno,"+
           "Content,Prince,Amount,Leav_number,Regtime,picture) values ('";
           sqlStr = sqlStr + dataFormat.toSql(abooks.getBookName()) + "','";
           sqlStr = sqlStr + abooks.getBookClass() + "','";
           sqlStr = sqlStr + dataFormat.toSql(abooks.getAuthor()) + "','";
           sqlStr = sqlStr + dataFormat.toSql(abooks.getPublish()) + "','";
           sqlStr = sqlStr + dataFormat.toSql(abooks.getBookNo()) + "','";
           sqlStr = sqlStr + dataFormat.toSql(abooks.getContent()) + "','";
           sqlStr = sqlStr + abooks.getPrince() + "','";
           sqlStr = sqlStr + abooks.getAmount() + "','";
           sqlStr = sqlStr + abooks.getAmount() + "',";
           sqlStr = sqlStr + "now()"+ ",'";
           sqlStr = sqlStr + abooks.getPicture()+"')";
                try{
                        System.out.print(sqlStr);
                        DataBase db = new DataBase();
                        //db.connect();
                        //stmt =db.conn.createStatement ();
                        db.stmt.execute(sqlStr);
                        db.finalize();
                        return true;
                }catch (SQLException sqle){
                  System.out.print(sqle.getMessage());
                        return false;
                }
        }
        /**
         * 完成图书修改
         * @return
         * @throws java.lang.Exception
         */
public boolean update() throws Exception {
  sqlStr = "update book set ";
  sqlStr = sqlStr + "bookname = '" + dataFormat.toSql(abooks.getBookName()) + "',";
  sqlStr = sqlStr + "bookclass = '" + abooks.getBookClass() + "',";
  sqlStr = sqlStr + "Author = '" + dataFormat.toSql(abooks.getAuthor()) + "',";
  sqlStr = sqlStr + "publish = '" + dataFormat.toSql(abooks.getPublish()) + "',";
  sqlStr = sqlStr + "bookno = '" + dataFormat.toSql(abooks.getBookNo()) + "',";
  sqlStr = sqlStr + "content = '" + dataFormat.toSql(abooks.getContent()) + "',";
  sqlStr = sqlStr + "prince = '" + abooks.getPrince() + "',";
  sqlStr = sqlStr + "Amount = '" + abooks.getAmount() + "',";
  sqlStr = sqlStr + "leav_number = '" + abooks.getLeav_number()+ "' ,";
  sqlStr = sqlStr + "picture = '" + abooks.getPicture() + "' ";
  sqlStr = sqlStr + "where id = " + abooks.getId();
                try{
                        DataBase db = new DataBase();
                        //db.connect();
                        //stmt =db.conn.createStatement ();
                        db.stmt.execute(sqlStr);
                        db.finalize();
                        return true;
                } catch (SQLException e){
                        System.out.print(e.getMessage());
                        return false;
                }

        }
        /**
         * 完成图书删除
         * @param aid
         * @return
         * @throws java.lang.Exception
         */
        public boolean delete( int aid ) throws Exception {
                sqlStr = "delete from book where id = "  + aid ;
                try
                {         DataBase db = new DataBase();
                          //db.connect();
                          //stmt =db.conn.createStatement ();
                          db.stmt.execute(sqlStr);
                          db.finalize();
                         return true;
                }
                catch (SQLException e)
                {
                        System.out.println(e);
                        return false;
                }
              }
              /**
               * 完成图书单本查询,用于支持页面的查看图书详细资料
               * @param newid
               * @return
               * @throws java.lang.Exception
               */
 public boolean getOnebook(int newid ) throws Exception {
     DataBase db = new DataBase();
     //db.connect();
     //stmt =db.conn.createStatement ();
     try {
        sqlStr="select  a.id,a.bookname,a.bookclass,b.classname,a.author,"+
        "a.publish,a.bookno,a.content,a.prince,a.amount,a.leav_number,"+
        "a.regtime,a.picture from book a,bookclass b where a.bookclass="+
        "b.id and a.id = " + newid ;
                        rs = db.stmt.executeQuery(sqlStr);
                        if (rs.next())
                        {	booklist = new Vector(1);
                                book book = new book();
                                book.setId(rs.getLong("id"));
                                book.setBookName(rs.getString("bookname"));
                                book.setBookClass(rs.getInt("bookclass"));
                                book.setClassname(rs.getString("classname"));
                                book.setAuthor(rs.getString("author"));
                                book.setPublish(rs.getString("publish"));
                                book.setBookNo(rs.getString("bookno"));
                                book.setContent(rs.getString("content"));
                                book.setPrince(rs.getFloat("prince"));
                                book.setAmount(rs.getInt("amount"));
                                book.setLeav_number(rs.getInt("leav_number"));
                                book.setRegTime(rs.getString("regtime"));
                                book.setPicture(rs.getString("picture"));
                                booklist.addElement(book);
                        } else {
                                rs.close();
                                return false;
                        }
                        rs.close();
                        db.finalize();
                        return true;
                }
                catch (SQLException e)
                {
                        return false;
                }
        }
        public int getPage() {				//显示的页码
                return page;
        }
        public void setPage(int newpage) {
                page = newpage;
        }
        public int getPageSize(){			//每页显示的图书数
                return pageSize;
        }
        public void setPageSize(int newpsize) {
                pageSize = newpsize;
        }
        public int getPageCount() {				//页面总数
                return pageCount;
        }
        public void setPageCount(int newpcount) {
                pageCount = newpcount;
        }
        public long getRecordCount() {
                return recordCount;
        }
        public void setRecordCount(long newrcount) {
                recordCount= newrcount;
        }
  public op_book() {
       }
}

⌨️ 快捷键说明

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