package com.java.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.java.model.Book;
import com.java.util.StringUtil;
public class BookDao {
public int bookAdd(Connection con,Book book)throws Exception{
String sql="insert into t_book values(null,?,?,?,?,?,?)";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, book.getBookName());
pstmt.setString(2, book.getAuthor());
pstmt.setString(3, book.getSex());
pstmt.setFloat(4, book.getPrice());
pstmt.setString(5, book.getBookDesc());
pstmt.setInt(6, book.getBookTypeId());
return pstmt.executeUpdate();
}
public ResultSet bookList(Connection con,Book book)throws Exception{
StringBuffer sb=new StringBuffer("select * from t_book b,t_bookType bt where b.bookTypeId=bt.id");
if(StringUtil.isNotEmpty(book.getBookName())){
sb.append(" and b.bookName like '%"+book.getBookName()+"%'");
}
if(StringUtil.isNotEmpty(book.getAuthor())){
sb.append(" and b.author like '%"+book.getAuthor()+"%'");
}
if(StringUtil.isNotEmpty(book.getSex())){
sb.append(" and b.sex = '"+book.getSex()+"'");
}
if(book.getBookTypeId()!=-1){
sb.append(" and b.bookTypeId = "+book.getBookTypeId());
}
PreparedStatement pstmt=con.prepareStatement(sb.toString());
return pstmt.executeQuery();
}
public int bookDelete(Connection con,String id)throws Exception{
String sql="delete from t_book where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, id);
return pstmt.executeUpdate();
}
public int bookModify(Connection con,Book book)throws Exception{
String sql="update t_book set bookName=?,author=?,sex=?,price=?,bookDesc=?,bookTypeId=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, book.getBookName());
pstmt.setString(2, book.getAuthor());
pstmt.setString(3, book.getSex());
pstmt.setFloat(4, book.getPrice());
pstmt.setString(5, book.getBookDesc());
pstmt.setInt(6, book.getBookTypeId());
pstmt.setInt(7, book.getId());
return pstmt.executeUpdate();
}
public boolean getBookByBookTypeId(Connection con,String bookTypeId)throws Exception{
String sql="select * from t_book where bookTypeId=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, bookTypeId);
ResultSet rs=pstmt.executeQuery();
return rs.next();
}
}
最近下载更多
hongdongdong LV14
2023年8月9日
婆婆12254 LV2
2023年6月12日
user0810 LV4
2023年1月5日
liys1234 LV9
2022年6月23日
testuser1234567 LV24
2022年5月31日
喃喵xxxx LV6
2022年5月11日
wyx065747 LV67
2022年4月2日
微信网友_5853711597064192 LV3
2022年3月1日
benbosn LV15
2022年2月11日
不愧是谁 LV2
2021年12月17日
最近浏览更多
无异偶 LV3
2024年12月30日
binzhuyou LV2
2024年7月4日
微信网友_7015663524368384 LV1
2024年5月30日
z1445234295
2024年3月11日
暂无贡献等级
asddwh LV13
2023年12月25日
huangzy LV12
2023年12月21日
微信网友_6786215447367680 LV5
2023年12月20日
微信网友_6445756515635200 LV3
2023年12月18日
xp95323 LV15
2023年11月27日
李朝磊 LV18
2023年11月18日

