/**
*
*/
package demo.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import demo.entity.Borrow;
import demo.util.DBUtil;
/**
* 对接borrow表的类
*
*/
public class BorrowDao {
/**
* 查询该借阅者当前是否有超期图书未归还
* @param readerId 借阅者id
* @return 当前有超期图书未归还:1 没有:-1
*/
public int selectNowTimeoutById(String readerId) {
Connection con = DBUtil.getConnection();
String sql = " select * from borrow where timeout=1 and time_return_real is null and id_reader = ?";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, readerId);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return 1;
}
}
catch (SQLException e) {
}
finally {
DBUtil.closeConnection(con);
}
}
return -1;
}
/**
* 归还图书时,根据num填写实际还书时间
* @param bookId
* @return 失败:-1 成功:1
*/
public int updateRealById(String bookId) {
Connection con = DBUtil.getConnection();
String sql = " update borrow set time_return_real = CURDATE() where id_book=? and time_return_real is NULL";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, bookId);
return ps.executeUpdate();
}
catch (SQLException e) {
return -1;
}
finally {
DBUtil.closeConnection(con);
}
}
return -1;
}
/**
* 续借时,修改应还时间,将应还时间修改为当前时间加一个月
* @param bookId
* @return
*/
public int updateShouldById(String bookId) {
Connection con = DBUtil.getConnection();
String sql = " update borrow set time_return_should = date_add(CURTATE(), interval 1 MONTH) where num = (SELECT a.num from(select num from borrow where id_book = ? and timeout!=1 and time_return_real is NULL) a )";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, bookId);
return ps.executeUpdate();
}
catch (SQLException e) {
return -1;
}
finally {
DBUtil.closeConnection(con);
}
}
return -1;
}
/**
* 续借次数加1
* @param bookId
* @return
*/
public int renew (String bookId) {
Connection con = DBUtil.getConnection();
String sql = " update borrow set renew = renew+1 where num = (SELECT a.num from(select num from borrow where id_book = ? and timeout!=1 and time_return_real is NULL) a )";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, bookId);
return ps.executeUpdate();
}
catch (SQLException e) {
return -1;
}
finally {
DBUtil.closeConnection(con);
}
}
return -1;
}
/**
* 返回续借次数,起始未1,续借两次后为3
* @param bookId
* @return
*/
public int returnRenewById(String bookId) {
Connection con = DBUtil.getConnection();
String sql = " SELECT renew from borrow where num = (select num from borrow where id_book = ? and timeout!=1 and time_return_real is NULL)";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, bookId);
ResultSet rs = ps.executeQuery();
int renew = 0;
if (rs.next()) {
renew = rs.getInt(1);
}
return renew;
}
catch (SQLException e) {
return 0;
}
finally {
DBUtil.closeConnection(con);
}
}
return 0;
}
/**
* 管理员当前借阅模糊查询
* @param bookId
* @param readId
* @param readerName
* @param bookName
* @return
*/
public List<Borrow> selectByOthers( String readerName, String bookName){
Connection con = DBUtil.getConnection();
String sql = "select id_book, book.name as bookname, id_reader, user.name as username, time_borrow, time_return_should from user,book,borrow where user.id=id_reader and book.id=id_book and time_return_real IS NULL and user.name like \"%\"?\"%\" and book.name like \"%\"?\"%\"";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, readerName);
ps.setString(2, bookName);
ResultSet rs = ps.executeQuery();
List<Borrow> borrowList = rsToBorrows(rs);
return borrowList;
}
catch (SQLException e) {
return null;
}
finally {
DBUtil.closeConnection(con);
}
}
return null;
}
/**
* 管理员历史借阅模糊查询
* @param bookId
* @param readId
* @param readerName
* @param bookName
* @return
*/
public List<Borrow> selectPastByOthers( String readerName, String bookName){
Connection con = DBUtil.getConnection();
String sql = "select id_book, book.name as bookname, id_reader, user.name as username, time_borrow, time_return_real from user,book,borrow where user.id=id_reader and book.id=id_book and time_return_real IS NOT NULL and user.name like \"%\"?\"%\" and book.name like \"%\"?\"%\"";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, readerName);
ps.setString(2, bookName);
ResultSet rs = ps.executeQuery();
List<Borrow> borrowList = rsToBorrows(rs);
return borrowList;
}
catch (SQLException e) {
return null;
}
finally {
DBUtil.closeConnection(con);
}
}
return null;
}
/**
* 管理员超时借阅模糊查询
* @param bookId
* @param readId
* @param readerName
* @param bookName
* @return
*/
public List<Borrow> selectOverByOthers( String readerName, String bookName){
Connection con = DBUtil.getConnection();
String sql = "select id_book, book.name as bookname, id_reader, user.name as username, time_return_should, time_return_real from user,book,borrow where user.id=id_reader and book.id=id_book and timeout=1 and user.name like \"%\"?\"%\" and book.name like \"%\"?\"%\"";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, readerName);
ps.setString(2, bookName);
ResultSet rs = ps.executeQuery();
List<Borrow> borrowList = rsToBorrows(rs);
return borrowList;
}
catch (SQLException e) {
return null;
}
finally {
DBUtil.closeConnection(con);
}
}
return null;
}
/**
* 管理员当前借阅查询,根据读者id和图书id和其他
* @param bookId
* @param readId
* @param readerName
* @param bookName
* @return
*/
public List<Borrow> selectByBookIdReaderId( String bookId, String readId, String readerName, String bookName){
Connection con = DBUtil.getConnection();
String sql = "select id_book, book.name as bookname, id_reader, user.name as username, time_borrow, time_return_should from user,book,borrow where user.id=id_reader and book.id=id_book and time_return_real IS NULL and book.id=? and user.id=? and user.name like \"%\"?\"%\" and book.name like \"%\"?\"%\"";
PreparedStatement ps = null;
if (con != null) {
try {
ps = con.prepareStatement(sql);
ps.setString(1, bookId);
ps.setString(2, readId);
ps.setString(3, readerName);
ps.setString(4, bookName);
ResultSet rs = ps.executeQuery();
List<Borrow> borrowList = rsToBorrows(rs);
return borrowList;
}
catch (SQLException e) {
return null;
}
finally {
DBUtil.closeConnection(con);
}
}
return null;
}
/**
* 管理员历史借阅查询,根据读者id和图书id和其他
* @param bookId
* @param readId
* @param readerName
* @param bookName
* @return
*/
public List<Borrow> selectPastByBookIdReaderId( String bookId, String readId, String readerName, String bookName){
Connection con = DBUtil.getConnection();
String sql = "select id_book, book.name as bookname, id_reader, user.name as username, time_borrow
没有合适的资源?快使用搜索试试~ 我知道了~
java图书管理系统项目源码

共99个文件
png:51个
java:38个
jar:3个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 70 浏览量
2024-06-16
10:33:57
上传
评论
收藏 8.99MB ZIP 举报
温馨提示
# 程序入口为src/demo/Main.java # 执行程序之前需要先填写properties文件中的password(数据库密码) # 不要修改properties文件中的booksystem数据库的名称 # 注册身份只能是借阅者,图书管理员和系统管理员只能通过系统管理员手动添加 # 系统管理员: 0000 00Aa # 图书管理员: 1111 11Aa # 借阅者: 2222 22Aa
资源推荐
资源详情
资源评论















收起资源包目录














































































































共 99 条
- 1
资源评论


酷爱码
- 粉丝: 1w+
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 【国家自然科学基金】支护强度基金支持热词逐年推荐【万方软件创新助手】.pdf
- Module10--Spring-Festival公开课教案教学设计课件案例试卷.ppt
- 软件服务协议合同(1).docx
- ios开发及上架流程.pdf
- (完整word版)大数据在旅游行业中的应用.doc
- bp神经网络算法(最新整理).pdf
- 网络信息化管理制度(1)(1).doc
- 《软件工程》试卷及答案---A卷--B卷.doc
- 人工智能时代企业财务会计向管理会计的转型研究(1).docx
- 酒店制度表格全集-酒店的信息化和管理标准化(2)(1).doc
- GIS原理与应用.ppt
- 单片机课程设计-简易电子时钟(2)(1).doc
- 电子商务与物流配送的现状及对策分析的论文-电子商务论文(1).docx
- 27年平凉市专业技术人员继续教育培训互联网+开放合作.pdf
- (完整版)15、基于单片机STC89C52的直流电机PWM调速控制系统.doc
- PLC控制锅炉恒压供水系统设计(1)(1).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
