package com.fengjing.store.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.fengjing.store.db.DB;
import com.fengjing.store.vo.Book;
public class BookDao {
//查询全部
@SuppressWarnings("unchecked")
public List queryAll(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
List list = null;
try {
conn = DB.getConnection();
stmt = DB.getStmt(conn);
String sql = "select * from titles";
rs = DB.getRs(stmt, sql);
list=new ArrayList();
while (rs.next()) {
Book book = new Book();
String isbn = rs.getString("isbn");
int isre = rs.getInt("isrecommend");
int subid = rs.getInt("subId");
String title = rs.getString("title");
int ednum = rs.getInt("editionNumber");
String copy = rs.getString("copyright");
int pubid = rs.getInt("publisherID");
double price =rs.getDouble("price");
String imageFile = rs.getString("imageFile");
book.setIsbn(isbn);
book.setIsRecommend(isre);
book.setSub(new SubCategoryDao().queryById(subid));
book.setTitle(title);
book.setEditionNumber(ednum);
book.setCopyRight(copy);
book.setPrice(price);
book.setImageFile(imageFile);
list.add(book);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
DB.close(conn, stmt, rs);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return list;
}
public Book queryById(String isbn){
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Book book = null;
try {
conn = DB.getConnection();
String sql = "select * from titles where isbn=?";
pstmt = DB.getPstmt(conn, sql);
pstmt.setString(1, isbn);
rs = pstmt.executeQuery();
if(rs.next()) {
book = new Book();
String isb = rs.getString("isbn");
int isre = rs.getInt("isrecommend");
int subid = rs.getInt("subId");
String title = rs.getString("title");
int ednum = rs.getInt("editionNumber");
String copy = rs.getString("copyright");
int pubid = rs.getInt("publisherID");
double price =rs.getDouble("price");
String imageFile = rs.getString("imageFile");
book.setIsbn(isb);
book.setIsRecommend(isre);
book.setSub(new SubCategoryDao().queryById(subid));
book.setTitle(title);
book.setEditionNumber(ednum);
book.setCopyRight(copy);
book.setPrice(price);
book.setImageFile(imageFile);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
DB.close(conn, pstmt, rs);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return book;
}
public int delete(String isbn){
Connection conn = null;
Statement stmt = null;
int i=0;
try {
conn = DB.getConnection();
stmt = DB.getStmt(conn);
String sql = "delete from titles where isbn='"+isbn+"'";
i = stmt.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return i;
}
public int update(Book book){
Connection conn = null;
PreparedStatement pstmt = null;
int i = 0;
try {
conn = DB.getConnection();
String sql="update titles set isrecommend=?,subId=?,title=?,editionNumber=?,copyright=?,imageFile=?,price=? where isbn=? ";
pstmt = DB.getPstmt(conn, sql);
pstmt.setInt(1,book.getIsRecommend());
pstmt.setInt(2,book.getSub().getSubId());
pstmt.setString(3,book.getTitle());
pstmt.setInt(4,book.getEditionNumber());
pstmt.setString(5, book.getCopyRight());
pstmt.setString(6, book.getImageFile());
pstmt.setDouble(7, book.getPrice());
pstmt.setString(8, book.getIsbn());
i = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
DB.close(conn, pstmt);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return i;
}
public int insert(Book book){
Connection conn = null;
PreparedStatement pstmt = null;
int i = 0;
try {
conn = DB.getConnection();
String sql="insert into titles values (?,?,?,?,?,?,?,?,?) ";
pstmt = DB.getPstmt(conn, sql);
pstmt.setString(1, book.getIsbn());
pstmt.setInt(2, book.getIsRecommend());
pstmt.setInt(3, book.getSub().getSubId());
pstmt.setString(4,book.getTitle());
pstmt.setInt(5,book.getEditionNumber());
pstmt.setString(6, book.getCopyRight());
pstmt.setInt(7, book.getPublisherID());
pstmt.setString(8,book.getImageFile());
pstmt.setDouble(9, book.getPrice());
i = pstmt.executeUpdate();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}finally{
try {
DB.close(conn, pstmt);
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
return i;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
jsp+servlet+javabean开发的购物车 (185个子文件)
title3.bmp 102KB
BookDao.class 6KB
UserDao.class 5KB
SubCategoryDao.class 5KB
UserServlet.class 4KB
SearchPageBean.class 4KB
BookOrderDao.class 4KB
RootCategoryDao.class 4KB
CartServlet.class 3KB
PLPageBean.class 3KB
PageBean.class 3KB
OrderServlet.class 3KB
LWPageBean.class 3KB
Book.class 2KB
LWServlet.class 2KB
DB.class 2KB
SystemFilter.class 2KB
BookOrder.class 2KB
LeaveWordDao.class 1KB
LeaveWord.class 1KB
SubCategory.class 1KB
RootCategory.class 989B
User.class 981B
SystemUser.class 979B
CartBean.class 788B
.classpath 743B
main.css 2KB
css.css 2KB
style.css 2KB
toc.css 620B
main-1.gif 290KB
newtitle.gif 202KB
bn01~.gif 49KB
bk.gif 6KB
msn.gif 4KB
c1.gif 2KB
c3.gif 2KB
c2.gif 2KB
splitcoin.gif 530B
upcoin.gif 523B
downcoin.gif 510B
lefticon.gif 507B
righticon.gif 507B
head_03_qs.gif 383B
arrowDn.gif 369B
arrowUp.gif 366B
top.gif 224B
qq.gif 169B
top01.gif 126B
2_clos.gif 114B
2_open.gif 111B
3_clos.gif 108B
3_open.gif 104B
icon1.gif 104B
bnbg1.gif 92B
2_none.gif 84B
topbt5.gif 82B
topbt4.gif 80B
topbt3.gif 80B
topbt2.gif 80B
topbt1.gif 80B
3_none.gif 77B
4_none.gif 69B
4_clos.gif 58B
leftbg.gif 44B
AdminTree.html 2KB
backframe.html 780B
MainFrame.html 767B
toptitle.html 567B
TestTV20.html 468B
welcome.html 344B
standard.jar 384KB
jstl.jar 20KB
BookDao.java 6KB
UserDao.java 5KB
UserServlet.java 4KB
SearchPageBean.java 4KB
SubCategoryDao.java 4KB
RootCategoryDao.java 4KB
BookOrderDao.java 3KB
CartServlet.java 3KB
PLPageBean.java 2KB
PageBean.java 2KB
LWPageBean.java 2KB
OrderServlet.java 2KB
Book.java 2KB
LWServlet.java 2KB
SystemFilter.java 1KB
DB.java 1KB
BookOrder.java 1KB
LeaveWordDao.java 909B
LeaveWord.java 842B
SubCategory.java 661B
User.java 541B
RootCategory.java 529B
SystemUser.java 518B
CartBean.java 373B
bn01.jpg 74KB
bn01~.jpg 49KB
bn01.jpg 39KB
共 185 条
- 1
- 2
feng200820
- 粉丝: 105
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0