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

📄 bookimpl.java

📁 jsp+servlet网上购物,是一个实现mvc的网站
💻 JAVA
字号:
package com.ebook.impl;import com.ebook.dao.*;import com.ebook.Entity.*;import java.sql.*;import java.util.*;public class BookImpl implements BookDao {    private Connection con;    public BookImpl(Connection con) {        this.con = con;    }    public ArrayList getBook() throws Exception {        PreparedStatement pstm;        String sql = "select* from book";        pstm = con.prepareStatement(sql);        ResultSet rs = pstm.executeQuery();        ArrayList list = new ArrayList();        while (rs.next()) {            Book book = new Book();            book.setBookId(rs.getInt("Bookid"));            book.setCategoryId(rs.getInt("Categoryid"));            book.setBookName(rs.getString("Bookname"));            book.setAuthor(rs.getString("Author"));            book.setBeforePrice(rs.getString("Beforeprice"));            book.setNowPrice(rs.getString("Nowprice"));            book.setPublishCompany(rs.getString("Publishcompany"));            book.setPublishDate(rs.getString("Publishdate"));            book.setDes(rs.getString("Des"));            book.setImage(rs.getString("Image"));            list.add(book);        }        return list;    }    public Book getOneBook(int id) throws Exception    {         PreparedStatement pstm;         String sql="select * from book where Bookid=?";         pstm=con.prepareStatement(sql);         pstm.setInt(1,id);         ResultSet rs=pstm.executeQuery();         Book book = new Book();         while(rs.next())         {                       book.setBookId(rs.getInt("Bookid"));            book.setCategoryId(rs.getInt("Categoryid"));            book.setBookName(rs.getString("Bookname"));            book.setAuthor(rs.getString("Author"));            book.setBeforePrice(rs.getString("Beforeprice"));            book.setNowPrice(rs.getString("Nowprice"));            book.setPublishCompany(rs.getString("Publishcompany"));            book.setPublishDate(rs.getString("Publishdate"));            book.setDes(rs.getString("Des"));            book.setImage(rs.getString("Image"));         }         return book;            }       public ArrayList getCateBook(int cateid) throws Exception       {          ArrayList list=new ArrayList();         PreparedStatement pstm;         String sql="select * from book where Categoryid=?";         pstm=con.prepareStatement(sql);         pstm.setInt(1,cateid);         ResultSet rs=pstm.executeQuery();                while(rs.next())         {            Book book = new Book();            book.setBookId(rs.getInt("Bookid"));            book.setCategoryId(rs.getInt("Categoryid"));            book.setBookName(rs.getString("Bookname"));            book.setAuthor(rs.getString("Author"));            book.setBeforePrice(rs.getString("Beforeprice"));            book.setNowPrice(rs.getString("Nowprice"));            book.setPublishCompany(rs.getString("Publishcompany"));            book.setPublishDate(rs.getString("Publishdate"));            book.setDes(rs.getString("Des"));            book.setImage(rs.getString("Image"));            list.add(book);         }         return list;       }          public ArrayList getNameBook(String name) throws Exception       {          ArrayList list=new ArrayList();         PreparedStatement pstm;         String sql="select * from book where Bookname like ?";         pstm=con.prepareStatement(sql);         pstm.setString(1, "%"+name+"%");         ResultSet rs=pstm.executeQuery();                while(rs.next())         {            Book book = new Book();            book.setBookId(rs.getInt("Bookid"));            book.setCategoryId(rs.getInt("Categoryid"));            book.setBookName(rs.getString("Bookname"));            book.setAuthor(rs.getString("Author"));            book.setBeforePrice(rs.getString("Beforeprice"));            book.setNowPrice(rs.getString("Nowprice"));            book.setPublishCompany(rs.getString("Publishcompany"));            book.setPublishDate(rs.getString("Publishdate"));            book.setDes(rs.getString("Des"));            book.setImage(rs.getString("Image"));            list.add(book);         }         return list;       }    /*    public void addBook(Book book)throws Exception    {        PreparedStatement pstm;        String sql="insert into book(Bookname,Categoryid) values(?,?)";        pstm=con.prepareStatement(sql);        pstm.setString(1, book.getBookName());        pstm.setInt(2, book.getCategoryId());        pstm.executeUpdate();    }*/}

⌨️ 快捷键说明

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