📄 bookdao.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -