package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import entity.Book;
import util.DatabaseConnection;
import util.DateUtil;
public class BookDao {
/**
* 通过图书Id 获取该图书信息
* @return
*/
public Book selectBookInfoById(int bookId){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
Book book = null;
try {
//连接上数据库
conn = DatabaseConnection.getConnection();
stmt=conn.createStatement();
String selectSql = "select * from book where id='"+bookId+"'";
rs=stmt.executeQuery(selectSql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String cover = rs.getString("cover");
float price = rs.getFloat("price");
String introduce = rs.getString("introduce");
String auther = rs.getString("auther");
String press = rs.getString("press");
Date publishDate = rs.getDate("publishDate");
int categoryId = rs.getInt("categoryId");
int special = rs.getInt("special");
int news = rs.getInt("news");
int sale = rs.getInt("sale");
book = new Book(id,name,cover,introduce,price,auther,press,publishDate,categoryId,special,news,sale);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
//关闭数据库连接
DatabaseConnection.close(rs,conn);
}
return book;
}
/**
* 获取精品推荐的图书
* @return
*/
public List<Book> selectSpecilBookList(){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
Book book = null;
List<Book> specilList = new ArrayList<Book>();
try {
//连接上数据库
conn = DatabaseConnection.getConnection();
stmt=conn.createStatement();
String selectSql = "select * from book where special='1'";
rs=stmt.executeQuery(selectSql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String cover = rs.getString("cover");
float price = rs.getFloat("price");
String introduce = rs.getString("introduce");
String auther = rs.getString("auther");
String press = rs.getString("press");
Date publishDate = rs.getDate("publishDate");
int categoryId = rs.getInt("categoryId");
int special = rs.getInt("special");
int news = rs.getInt("news");
int sale = rs.getInt("sale");
book = new Book(id,name,cover,introduce,price,auther,press,publishDate,categoryId,special,news,sale);
specilList.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return specilList;
}
/**
* 获取最新出版的图书
* @return
*/
public List<Book> selectNewsBookList(){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
Book book = null;
List<Book> newsList = new ArrayList<Book>();
try {
//连接上数据库
conn = DatabaseConnection.getConnection();
stmt=conn.createStatement();
String selectSql = "select * from book where news='1'";
rs=stmt.executeQuery(selectSql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String cover = rs.getString("cover");
float price = rs.getFloat("price");
String introduce = rs.getString("introduce");
String auther = rs.getString("auther");
String press = rs.getString("press");
Date publishDate = rs.getDate("publishDate");
int categoryId = rs.getInt("categoryId");
int special = rs.getInt("special");
int news = rs.getInt("news");
int sale = rs.getInt("sale");
book = new Book(id,name,cover,introduce,price,auther,press,publishDate,categoryId,special,news,sale);
newsList.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return newsList;
}
/**
* 获取打折出售的图书
* @return
*/
public List<Book> selectSaleBookList(){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
Book book = null;
List<Book> saleList = new ArrayList<Book>();
try {
//连接上数据库
conn = DatabaseConnection.getConnection();
stmt=conn.createStatement();
String selectSql = "select * from book where sale='1'";
rs=stmt.executeQuery(selectSql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String cover = rs.getString("cover");
float price = rs.getFloat("price");
String introduce = rs.getString("introduce");
String auther = rs.getString("auther");
String press = rs.getString("press");
Date publishDate = rs.getDate("publishDate");
int categoryId = rs.getInt("categoryId");
int special = rs.getInt("special");
int news = rs.getInt("news");
int sale = rs.getInt("sale");
book = new Book(id,name,cover,introduce,price,auther,press,publishDate,categoryId,special,news,sale);
saleList.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return saleList;
}
/**
* 根据类名查询图书信息
* @return
*/
public List<Book> selectBookListByCategory(int categoryId){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
Book book = null;
List<Book> saleList = new ArrayList<Book>();
try {
//连接上数据库
conn = DatabaseConnection.getConnection();
stmt=conn.createStatement();
String selectSql = "select * from book where categoryId='"+categoryId+"'";
rs=stmt.executeQuery(selectSql);
while(rs.next()){
int id = rs.getInt("id");
String name = rs.getString("name");
String cover = rs.getString("cover");
float price = rs.getFloat("price");
String introduce = rs.getString("introduce");
String auther = rs.getString("auther");
String press = rs.getString("press");
Date publishDate = rs.getDate("publishDate");
int cateId = rs.getInt("categoryId");
int special = rs.getInt("special");
int news = rs.getInt("news");
int sale = rs.getInt("sale");
book = new Book(id,name,cover,introduce,price,auther,press,publishDate,cateId,special,news,sale);
saleList.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return saleList;
}
/**
* 添加图书
* @param book
* @return
*/
public boolean insertBook(Book book){
Connection conn=null;//用于数据库的连接
Statement stmt=null;//用于将SQL语句发送到数据库中
ResultSet rs=null;//用于保存所有符合SQL语句条件的所有数据项
boolean insertResult=false;
String cover = book.getCover();
String name = book.getBookName();
String introduce = book.getIntroduce();
double price = book.getPrice();
String press = book.getPress();
Date date = book.getPublishDate();
String auther = book.getAuther();
String insertSql = "insert into book (name,cover,price,introduce,auther,press,publishDate) values ('"+name+"','"+cover+"','"+price+"','"+introduce+"','"+auther+"','"+press+"','"+da
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
纯JavaWeb基础开发的网上书店项目 (219个子文件)
BookDao.class 9KB
IndentDao.class 7KB
CustomerDao.class 4KB
CategoryDao.class 4KB
ModifyBookServlet.class 4KB
AdminDao.class 4KB
Book.class 4KB
IndentService.class 3KB
AddBookServlet.class 3KB
Indent.class 3KB
splitPage.class 3KB
BuyBookServlet.class 2KB
ShowPersonalInfoServlet.class 2KB
SubmitOrderServlet.class 2KB
RightServlet.class 2KB
BookService.class 2KB
DeleteIndentServlet.class 2KB
UserLoginServlet.class 2KB
DeleteCategoryServlet.class 2KB
AdminLoginServlet.class 2KB
GetCategoryIdServlet.class 2KB
DatabaseConnection.class 2KB
IsExistAdminIdServlet.class 2KB
ModifyUserInfoServlet.class 2KB
IsExistUserIdServlet.class 2KB
ShowBookServlet.class 2KB
UserRegisterServlet.class 2KB
GetBookIdServlet.class 2KB
ModifyCategoryServlet.class 2KB
AddAdminServlet.class 2KB
HandelBookSpecialServlet.class 2KB
UserLogoutServlet.class 2KB
HandelBookNewsServlet.class 2KB
HandelBookSaleServlet.class 2KB
ModifyUserPwdServlet.class 2KB
ModifyAdminPwdServlet.class 2KB
SignIndentServlet.class 2KB
GetIndentIdServlet.class 2KB
DeleteAdminServlet.class 2KB
AddCategoryServlet.class 2KB
ShowCategoryBookServlet.class 2KB
GetAdminIdServlet.class 1KB
GetUserIdServlet.class 1KB
ViewBookDetailsServlet.class 1KB
Items.class 1KB
User.class 1KB
LanguageFilter.class 1KB
CategoryService.class 1KB
CustomerService.class 1KB
AdminService.class 1KB
Category.class 886B
DateUtil.class 877B
Admin.class 776B
Test.class 755B
.classpath 903B
org.eclipse.wst.common.component 464B
org.eclipse.wst.jsdt.ui.superType.container 49B
style.css 9KB
style.css 1KB
网上书店界面以及功能说明.docx 14.98MB
about.gif 16KB
prod1.gif 13KB
prod2.gif 13KB
footer_bg.gif 12KB
thumb1.gif 8KB
about_right.gif 7KB
top_bg.gif 7KB
thumb2.gif 7KB
thumb3.gif 6KB
center_bg.gif 4KB
border.gif 2KB
logo.gif 2KB
logo.gif 2KB
special_icon.gif 2KB
new_icon.gif 2KB
discount_icon.gif 2KB
cart.gif 1KB
bullet4.gif 1KB
bullet5.gif 1KB
bullet3.gif 1KB
bullet1.gif 1KB
footer_logo.gif 723B
top_logo.gif 723B
new_prod_box.gif 556B
register_bt.gif 556B
delete.gif 341B
left_menu_bullet.gif 281B
box_top.gif 262B
box_bottom.gif 262B
set.gif 213B
edit.gif 118B
query.gif 100B
box_center.gif 93B
menu_2.gif 76B
menu_1.gif 74B
main_16.gif 67B
cancle.gif 65B
cos.jar 56KB
BookDao.java 12KB
IndentDao.java 7KB
共 219 条
- 1
- 2
- 3
资源评论
zyy_sunshine
- 粉丝: 45
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功