/**
*
*/
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 下载量 26 浏览量
2024-06-16
10:33:57
上传
评论
收藏 8.99MB ZIP 举报
温馨提示
# 程序入口为src/demo/Main.java # 执行程序之前需要先填写properties文件中的password(数据库密码) # 不要修改properties文件中的booksystem数据库的名称 # 注册身份只能是借阅者,图书管理员和系统管理员只能通过系统管理员手动添加 # 系统管理员: 0000 00Aa # 图书管理员: 1111 11Aa # 借阅者: 2222 22Aa
资源推荐
资源详情
资源评论
收起资源包目录
sophomore---java-course-design-master.zip (99个子文件)
sophomore---java-course-design-master
lib
mybatis-3.0.1.jar 595KB
druid-1.0.9.jar 1.76MB
mysql-connector-java-8.0.28.jar 2.36MB
.classpath 575B
.settings
org.eclipse.jdt.core.prefs 767B
src
demo
Session.java 470B
dao
BorrowDao.java 26KB
UserDao.java 13KB
BookDao.java 9KB
MessageDao.java 4KB
view
Reader_Frame.java 10KB
MessageDetail.java 3KB
Li_lsjy.java 7KB
Re_cqjy.java 4KB
Ad_yhgl.java 12KB
BookBorrow.java 4KB
Re_ly.java 3KB
Re_dqjy.java 9KB
UpdateUserDetail.java 9KB
Li_tsgl.java 13KB
Li_dqjy.java 12KB
InsertUser.java 8KB
Li_cqjy.java 7KB
BookDetail.java 6KB
Administrator_Frame.java 7KB
ReturnBook.java 3KB
UserDetail.java 5KB
Smjs.java 10KB
Grzy.java 20KB
Li_ckly.java 11KB
Login.java 13KB
Librarian_Frame.java 10KB
InsertBook.java 9KB
RenewBook.java 3KB
Re_lsjy.java 6KB
UpdateBookDetail.java 10KB
entity
Message.java 789B
Book.java 2KB
Borrow.java 1KB
User.java 1KB
Main.java 351B
util
DBUtil.java 3KB
SwingUtil.java 905B
booksystem.sql 426KB
img
hnnydx.png 2.45MB
shumujiansuo.png 11KB
huozhe.png 4KB
用户注册.png 6KB
login_user.png 8KB
dqjy.png 9KB
xiyouji.png 4KB
reader.png 20KB
tianlongbabu.png 5KB
langtuteng.png 3KB
lishijieyue.png 12KB
lsjy.png 6KB
main_img.png 1.19MB
tushuguanli.png 6KB
用户.png 5KB
mrtp.png 5KB
yhgl.png 8KB
jijingdechuntian.png 4KB
gerenzhuye.png 12KB
sanguoyanyi.png 4KB
sys_adm.png 20KB
gerenziliao.png 13KB
zhuifengzhengderen.png 5KB
yonghuguanli.png 23KB
bainiangudu.png 5KB
book_adm.png 17KB
tianjia.png 6KB
图书管理.png 4KB
mrtx.png 2KB
图书详情.png 5KB
sousuo.png 10KB
cqjy.png 7KB
警告.png 6KB
用户管理.png 8KB
修改信息.png 4KB
dangqianjieyue.png 5KB
图书馆.png 6KB
账号.png 4KB
登录.png 3KB
ziyuan.png 20KB
w7gaoshoubaodian.png 4KB
修改密码.png 9KB
ly.png 4KB
chaoshi.png 14KB
womensa.png 4KB
注册.png 5KB
login1.png 320KB
liuyan.png 16KB
图书.png 10KB
chaxun.png 10KB
密码.png 4KB
properties 103B
readme 298B
.project 370B
.gitignore 6B
共 99 条
- 1
资源评论
酷爱码
- 粉丝: 8728
- 资源: 1903
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Android四种Activity的加载模式最新版本
- androidcamera(一)camera模组CMM介绍2.55MB最新版本
- Android-listview与adapter用法最新版本
- android修改system.img方法最新版本
- PID控制pidarduino库源码.rar
- Win7安装Android-Studio方法详解最新版本
- C++ 智能指针家族中的黄金搭档:std::shared-ptr 与 std::weak-ptr 协同工作机制全解析
- 基于中科院seetaface2进行封装的JAVA人脸识别算法库,支持人脸识别、1:1比对、1:N比对 seetaface2
- YOLOv3 多尺度方法改进与特征融合的深度探索与实现
- 小程序修改-网易云音乐.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功