package com.book.dao.impl;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.book.dao.BaseDao;
import com.book.dao.DaoFactory;
import com.book.dao.IBookDao;
import com.book.entity.Book;
import com.book.entity.Borrow;
import com.book.util.DateUtils;
import com.mysql.cj.util.Util;
import cn.hutool.core.lang.Console;
public class BookDaoImpl extends BaseDao implements IBookDao {
public Book selectByISBN(String ISBN) {
Book m = new Book();
String sql = "select * from book a LEFT OUTER JOIN book_sort b ON a.`sort_id` = b.`sort_id` where ISBN = ?";
Object[] obj = { ISBN };
ResultSet rs = selectJDBC(sql, obj);
try {
while (rs.next()) {
m.setISBN(rs.getString("iSBN"));
m.setBook_author(rs.getString("book_author"));
m.setBook_name(rs.getString("book_name"));
m.setBook_borrow(rs.getInt("book_borrow"));
m.setBook_price(rs.getBigDecimal("book_price"));
m.setBook_pub(rs.getString("book_pub"));
m.setBook_record(rs.getString("book_record"));
m.setSort_id(rs.getInt("sort_id"));
m.setSort_name(rs.getString("sort_name"));
}
return m;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
closeJDBC();
}
}
public List<Book> selectByName(String name) {
List<Book> lists = new ArrayList<Book>();
String sql = "select * from book a LEFT OUTER JOIN book_sort b ON a.`sort_id` = b.`sort_id` where book_name like \"%\"?\"%\"";
Object[] obj = { name };
ResultSet rs = selectJDBC(sql, obj);
try {
while (rs.next()) {
Book m = new Book();
m.setISBN(rs.getString("iSBN"));
m.setBook_author(rs.getString("book_author"));
m.setBook_name(rs.getString("book_name"));
m.setBook_borrow(rs.getInt("book_borrow"));
m.setBook_price(rs.getBigDecimal("book_price"));
m.setBook_pub(rs.getString("book_pub"));
m.setBook_record(rs.getString("book_record"));
m.setSort_id(rs.getInt("sort_id"));
m.setSort_name(rs.getString("sort_name"));
lists.add(m);
}
return lists;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
closeJDBC();
}
}
public boolean checkIsExist(String id) {
String sql = "select ISBN from book where ISBN = ?";
Object[] obj = { id };
ResultSet rs = selectJDBC(sql, obj);
try {
if (rs.next()) {
return true;
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
closeJDBC();
}
}
public int insert(Book m) {
boolean result = checkIsExist(m.getISBN());
if (result) {
return -1;
}
String sql = "insert into book (ISBN, book_name, book_author, book_pub, book_borrow, sort_id, book_record, book_price) values (?,?,?,?,?,?,?,?)";
Object[] obj = { m.getISBN(), m.getBook_name(), m.getBook_author(), m.getBook_pub(), m.getBook_borrow(),
m.getSort_id(), m.getBook_record(), m.getBook_price() };
int lines = updateJDBC(sql, obj);
if (lines > 0) {
closeJDBC();
return 1;
}
closeJDBC();
return 0;
}
public int update(Book m, String ISBN) {
String sql = "update book set ISBN = ?, book_name = ?, book_author = ?, book_pub = ?, book_borrow = ?, sort_id = ?, book_record = ?, book_price = ? where ISBN = ?";
Object[] obj = { m.getISBN(), m.getBook_name(), m.getBook_author(), m.getBook_pub(), m.getBook_borrow(),
m.getSort_id(), m.getBook_record(), m.getBook_price(), ISBN };
int lines = updateJDBC(sql, obj);
if (lines > 0) {
return 1;
}
return 0;
}
public List<Book> selectList() {
List<Book> lists = new ArrayList<Book>();
// String sql = "select * from book";
// 左外连接查询
String sql = "SELECT * FROM book a LEFT OUTER JOIN book_sort b ON a.`sort_id` = b.`sort_id`";
Object[] obj = {};
ResultSet rs = selectJDBC(sql, obj);
try {
while (rs.next()) {
Book m = new Book();
m.setISBN(rs.getString("ISBN"));
m.setBook_author(rs.getString("book_author"));
m.setBook_name(rs.getString("book_name"));
m.setBook_borrow(rs.getInt("book_borrow"));
m.setBook_price(rs.getBigDecimal("book_price"));
m.setBook_pub(rs.getString("book_pub"));
m.setBook_record(rs.getString("book_record"));
m.setSort_id(rs.getInt("sort_id"));
m.setSort_name(rs.getString("sort_name"));
lists.add(m);
}
return lists;
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
closeJDBC();
}
}
public int deleteByISBN(String ISBN) {
String sql = "delete from book where ISBN = ?";
Object[] obj = { ISBN };
int lines = updateJDBC(sql, obj);
if (lines > 0) {
closeJDBC();
return 1;
}
closeJDBC();
return 0;
}
/**
* 借阅操作,修改book的book_borrow的值,0为可借阅,1为已借阅,另外在借阅表添加借阅书籍的数据
*
* @param ISBN
* 书唯一编号
* @param s_id
* 借阅人编号
* @param borrow_date
* 借阅日期(一般为当天)
* @param expect_return_date
* 归还日期
* @return
*/
public boolean updateBookStatus(String ISBN, String s_id, String borrow_date, String expect_return_date) {
Book m = new Book();
String sql = "select * from book where ISBN = ?";
Object[] obj = { ISBN };
ResultSet rs = selectJDBC(sql, obj);
try {
while (rs.next()) {
m.setISBN(rs.getString("iSBN"));
m.setBook_author(rs.getString("book_author"));
m.setBook_name(rs.getString("book_name"));
if (rs.getInt("book_borrow") != 0) {
return false;
}
m.setBook_borrow(1);
m.setBook_price(rs.getBigDecimal("book_price"));
m.setBook_pub(rs.getString("book_pub"));
m.setBook_record(rs.getString("book_record"));
m.setSort_id(rs.getInt("sort_id"));
}
int result = update(m, ISBN);
if (result == 0) {
System.out.println("==图书更新状态失败");
return false;
}
// 在借阅表中添加数据
Borrow borrow = new Borrow();
borrow.setBook_borrow(m.getBook_borrow());
borrow.setBook_name(m.getBook_name());
borrow.setBorrow_date(borrow_date);
borrow.setExpect_return_date(expect_return_date); // 预计归还日期由用户设置
borrow.setISBN(m.getISBN());
borrow.setPrice(m.getBook_price());
borrow.setReturn_date(expect_return_date); // 当归还时才设置日期
borrow.setS_id(s_id);
result = DaoFactory.getIBorrowDaoInstance().insert(borrow);
if (result == 0) {
System.out.println("==借阅插入数据失败");
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
closeJDBC();
}
}
/**
* 归还操作
*/
public boolean returnBookStatus(String ISBN, String return_date) {
Book m = new Book();
String sql = "select * from book where ISBN = ?";
Object[] obj = { ISBN };
ResultSet rs = selectJDBC(sql, obj);
try {
while (rs.next()) {
m.setISBN(rs.getString("iSBN"));
m.setBook_author(rs.getString("book_author"));
m.setBook_name(rs.getString("book_name"));
if (rs.getInt("book_borrow") != 1) {
return false;
}
m.setBook_borrow(0);
m.setBook_price(rs.getBigDecimal("book_price"));
m.setBook_pub(rs.getString("book_pub"));
m.setBook_record(rs.getString("book_record"));
m.setSort_id(rs.getInt("sort_id"));
}
int result = update(m, ISBN);
if (result == 0) {
System.out.println("==图书更新状态失败");
return false;
}
// 在借阅表中修改数据
Borrow borrow = new Borrow();
borrow.setISBN(m.getISBN());
borrow.setBook_borrow(2); //借阅表中2为已归还
borrow.setReturn_date(return_date); // 当归还时才设置日期
result = DaoFactory.getIBorrowDaoInstance().update_returnbook(borrow);
if (result == 0) {
System.out.println("==借阅修改数据失败");
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
closeJDBC();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于JSP+Servlet+JDBC+mysql的图书管理系统源码(课程设计).zip 图书管理系统项目使用eclipse开发工具和MySql数据库进行开发,maven方式创建项目,编码格式为utf-8(如出现乱码可改成utf-8), 项目分成三层架构,数据访问层、业务逻辑层和表现层,并没有使用框架等复杂的技术,所以页面上比较简单。 这里Servlet我只做数据返回,所以完全可以是实现前后端分离, 前后端分离的话推荐使用vue,如果不分离也可以使用layer或其它前端框架。 通过这个项目对JSP、Servlet、JDBC、mysql数据库等技术有一个初步的认识和理解,同时也希望能够帮助有需要的朋友。 Mysql数据库和服务器 我使用的数据库版本为8.0.15; 服务器为Tocmat9.0.2; 数据表在src/test/resources的sql文件夹下。 项目功能 按使用人员分为两类: 一、学生 1.通过图书编号ISBN或书名查询图书信息; 2.可以对图书进行借阅操作; 3.查询自己的借阅的书籍,并对其进行归还操作。 二、管理员 1.显示图书馆所有的图书,或者通过书编号ISBN
资源推荐
资源详情
资源评论
收起资源包目录
基于JSP+Servlet+JDBC+mysql的图书管理系统源码(课程设计).zip (312个子文件)
$PRODUCT_WORKSPACE_FILE$ 489B
BookDaoImpl.class 8KB
BookDaoImpl.class 8KB
BookDaoImpl.class 8KB
BookDaoImpl.class 8KB
BorrowDaoImpl.class 5KB
BorrowDaoImpl.class 5KB
BorrowDaoImpl.class 5KB
BorrowDaoImpl.class 5KB
StudentDaoImpl.class 5KB
StudentDaoImpl.class 5KB
StudentDaoImpl.class 5KB
StudentDaoImpl.class 5KB
ManagerDaoImpl.class 4KB
ManagerDaoImpl.class 4KB
ManagerDaoImpl.class 4KB
ManagerDaoImpl.class 4KB
BookSortDaoImpl.class 4KB
BookSortDaoImpl.class 4KB
BookSortDaoImpl.class 4KB
EditBookServlet.class 3KB
EditBookServlet.class 3KB
EditBookServlet.class 3KB
AddBookServlet.class 3KB
AddBookServlet.class 3KB
AddBookServlet.class 3KB
StudentRegisterServlet.class 3KB
StudentRegisterServlet.class 3KB
StudentRegisterServlet.class 3KB
ManagerRegisterServlet.class 3KB
ManagerRegisterServlet.class 3KB
ManagerRegisterServlet.class 3KB
BaseDao.class 2KB
BaseDao.class 2KB
BaseDao.class 2KB
BaseDao.class 2KB
StudentLoginServlet.class 2KB
StudentLoginServlet.class 2KB
StudentLoginServlet.class 2KB
ManagerLoginServlet.class 2KB
ManagerLoginServlet.class 2KB
ManagerLoginServlet.class 2KB
BorrowBookServlet.class 2KB
AddBookSortServlet.class 2KB
AddBookSortServlet.class 2KB
AddBookSortServlet.class 2KB
Book.class 2KB
Book.class 2KB
Book.class 2KB
Book.class 2KB
Borrow.class 2KB
Borrow.class 2KB
Borrow.class 2KB
Borrow.class 2KB
BorrowBookServlet.class 2KB
BorrowBookServlet.class 2KB
Student.class 2KB
Student.class 2KB
Student.class 2KB
Student.class 2KB
ReturnBookServlet.class 2KB
ReturnBookServlet.class 2KB
ReturnBookServlet.class 2KB
QueryBorrowByIdServlet.class 2KB
QueryBorrowByIdServlet.class 2KB
QueryBorrowByIdServlet.class 2KB
QueryBookByNameServlet.class 2KB
QueryBookByNameServlet.class 2KB
QueryBookByNameServlet.class 2KB
QueryBorrowByISBNServlet.class 2KB
QueryBorrowByISBNServlet.class 2KB
QueryBorrowByISBNServlet.class 2KB
QueryBookByISBNServlet.class 2KB
QueryBookByISBNServlet.class 2KB
QueryBookByISBNServlet.class 2KB
DeleteBookServlet.class 2KB
DeleteBookServlet.class 2KB
DeleteBookServlet.class 2KB
BookServiceImpl.class 2KB
BookServiceImpl.class 2KB
BookServiceImpl.class 2KB
BookServiceImpl.class 2KB
ManagerServiceImpl.class 2KB
ManagerServiceImpl.class 2KB
ManagerServiceImpl.class 2KB
ManagerServiceImpl.class 2KB
StudentServiceImpl.class 2KB
StudentServiceImpl.class 2KB
StudentServiceImpl.class 2KB
StudentServiceImpl.class 2KB
BookSortServlet.class 2KB
BookSortServlet.class 2KB
BookSortServlet.class 2KB
ServiceFactory.class 2KB
ServiceFactory.class 2KB
ServiceFactory.class 2KB
ServiceFactory.class 2KB
BorrowServlet.class 2KB
BorrowServlet.class 2KB
BorrowServlet.class 2KB
共 312 条
- 1
- 2
- 3
- 4
资源评论
Make程序设计
- 粉丝: 5725
- 资源: 3570
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功