首页>代码>java swing图书馆管理系统-管理员操作和学生借还书>/bookManager/src/com/book/dao/BorrowDetailDao.java
package com.book.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.book.model.BorrowDetail;
import com.book.util.StringUtil;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class BorrowDetailDao {
	
	public ResultSet list(Connection con,BorrowDetail borrowDetail)throws Exception{
		StringBuffer sb=new StringBuffer("SELECT bd.*,u.username,b.book_name from borrowdetail bd,user u,book b where u.id=bd.user_id and b.id=bd.book_id");
		if(borrowDetail.getUserId() != null){
			sb.append(" and u.id = ?");
		}
		if(borrowDetail.getStatus() != null){
			sb.append(" and bd.status = ?");
		}
		if(borrowDetail.getBookId() != null){
			sb.append(" and bd.book_id = ?");
		}
		
		sb.append("  order by bd.id");
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sb.toString());
		if(borrowDetail.getUserId() != null){
			pstmt.setInt(1, borrowDetail.getUserId());
		}
		if(borrowDetail.getStatus() != null && borrowDetail.getBookId() != null){
			pstmt.setInt(2, borrowDetail.getStatus());
			pstmt.setInt(3, borrowDetail.getBookId());
		}
		return pstmt.executeQuery();
	}

	public int add(Connection con, BorrowDetail borrowDetail) throws Exception {
		String sql = "insert into borrowdetail (user_id,book_id,status,borrow_time) values (?,?,?,?)";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		pstmt.setInt(1, borrowDetail.getUserId());
		pstmt.setInt(2, borrowDetail.getBookId());
		pstmt.setInt(3, borrowDetail.getStatus());
		pstmt.setLong(4, borrowDetail.getBorrowTime());
		return pstmt.executeUpdate();
		
	}

	public int returnBook(Connection con,BorrowDetail detail)throws Exception {
		String sql = "update borrowdetail set status = ? ,return_time = ? where id = ?";
		PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
		pstmt.setInt(1, detail.getStatus());
		pstmt.setLong(2, detail.getReturnTime());
		pstmt.setInt(3, detail.getBorrowId());
		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日
最近浏览更多
pxqtsht  LV16 2月21日
无异偶  LV3 2024年12月30日
xxyylu  LV2 2024年12月4日
ZALZXB20030525 2024年7月1日
暂无贡献等级
sodkj123  LV16 2024年4月29日
小小白银110  LV1 2024年1月2日
偷喝汽水 2023年12月26日
暂无贡献等级
lshlsh 2023年12月25日
暂无贡献等级
huangzy  LV12 2023年12月21日
夜猫子111  LV2 2023年11月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友