bookdao.java
来自「电子商务网站中实现分页的源代码」· Java 代码 · 共 42 行
JAVA
42 行
package com.monitor.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.monitor.bean.BookBean;
public class BookDao {
DBConnection db = null;
public ArrayList<BookBean> getAllBooks(String strSql) throws SQLException, ClassNotFoundException{
db = new DBConnection();
ResultSet rs = db.executeAllQuery(strSql);
ArrayList<BookBean> books = new ArrayList<BookBean>();
while(rs.next()){
BookBean book = new BookBean();
book.setBid(rs.getInt(1));
book.setBname(rs.getString(2));
book.setBprice(rs.getFloat(3));
books.add(book);
}
db.closeConnection();
return books;
}
public BookBean getSingleBook(int id) throws SQLException, ClassNotFoundException{
ArrayList<BookBean> books = this.getAllBooks("select * from books where bid="+id);
return books.get(0);
}
public int getAllCount() throws SQLException, ClassNotFoundException{
db = new DBConnection();
ResultSet rs = db.executeAllQuery("select count(*) from books");
if(rs.next()){
return rs.getInt(1);
}else{
return 0;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?