package com.book.dao;
import java.util.List;
import com.book.model.BookType;
import com.book.util.StringUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class BookTypeDao {
// ͼ��������
public int add(Connection con,BookType bookType)throws Exception{
//�Ȳ�ѯ�Ƿ���һ��������
String sql="select * from book_type where type_name = ?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, bookType.getTypeName());
ResultSet resultSet = pstmt.executeQuery();
while(resultSet.next()){
return 2;
}
sql="insert into book_type (type_name,remark) values(?,?)";
PreparedStatement pstmt1=con.prepareStatement(sql);
pstmt1.setString(1, bookType.getTypeName());
pstmt1.setString(2, bookType.getRemark());
return pstmt1.executeUpdate();
}
//��ѯͼ�����
public ResultSet list(Connection con,BookType bookType)throws Exception{
StringBuffer sb=new StringBuffer("select * from book_type");
if(!StringUtil.isEmpty(bookType.getTypeName())){
sb.append(" and type_name like '%"+bookType.getTypeName()+"%'");
}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
// PreparedStatement pstmt=con.prepareStatement("select * from book_type");
return pstmt.executeQuery();
}
//ɾ��ͼ�����
public int delete(Connection con,String id)throws Exception{
//�Ȳ�ѯ��������Ƿ����鼮
String sql="select b.* from book b left join book_type bt on b.type_id = bt.id where bt.id =? ";
PreparedStatement pstmt1=con.prepareStatement(sql);
pstmt1.setString(1, id);
ResultSet query = pstmt1.executeQuery();
int number =0;
while(query.next()){
number++;
}
if(number > 0){
return 3;
}
//�ж���������Ƿ����1
sql="select * from book_type";
PreparedStatement pstmt2=con.prepareStatement(sql);
ResultSet resultSet = pstmt2.executeQuery();
int count = 0;
while(resultSet.next()){
count++;
}
if(count<2){
return 2;
}
sql="delete from book_type where id=?";
PreparedStatement pstmt3=con.prepareStatement(sql);
pstmt3.setString(1, id);
return pstmt3.executeUpdate();
}
// ����ͼʾ���
public int update(Connection con,BookType bookType)throws Exception{
String sql="update book_type set type_name=?,remark=? where id=?";
PreparedStatement pstmt=con.prepareStatement(sql);
pstmt.setString(1, bookType.getTypeName());
pstmt.setString(2, bookType.getRemark());
pstmt.setInt(3, bookType.getTypeId());
return pstmt.executeUpdate();
}
}
最近下载更多
xxyylu LV2
2024年12月4日
lsglsg9 LV23
2023年12月20日
sunshine9920 LV12
2023年10月23日
hongdongdong LV14
2023年8月9日
12345681 LV2
2023年6月10日
gxluchuan LV1
2023年4月7日
lolokei LV1
2022年10月10日
喃喵xxxx LV6
2022年9月6日
zxcvbnm1580 LV1
2022年6月15日
testuser1234567 LV24
2022年5月31日

最近浏览