/**
*
*/
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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
# 程序入口为src/demo/Main.java Java课程设计,图书管理系统,swing+jdbc+MySQL 项目源码 # 执行程序之前需要先填写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
资源评论
哆啦哆啦S梦
- 粉丝: 193
- 资源: 517
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于C#实现SQLite患者信息管理数据库操作技术方案
- 【python毕业设计】食堂外卖系统源码(完整前后端+mysql+说明文档).zip
- 【python毕业设计】摄影交流平台源码(完整前后端+mysql+说明文档).zip
- 【python毕业设计】平南盛世名城小区疫情防控系统源码(完整前后端+mysql+说明文档+LW).zip
- qt5半成品飞机大战小游戏
- 基于springboot的“衣依”服装销售平台的设计与实现(代码+数据库+LW)
- 【python毕业设计】旅游信息管理系统源码(完整前后端+mysql+说明文档).zip
- 【python毕业设计】基于python的图书馆管理系统源码(完整前后端+mysql+说明文档+LW).zip
- 计算机语言学中n-gram
- (全新整理)清科政府引导基金数据(1990-2023年)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功