package com.hafele.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import javax.swing.JOptionPane; import com.hafele.model.BackBook; import com.hafele.util.DbHelper; /** * @author Dragon Wen E-mail:18475536452@163.com * @version 创建时间:2017年10月10日 下午4:14:31 * 图书归还数据库操作类 */ public class BackBookDao { //获取图书归还信息 public static List<BackBook> selectBookBack(String readerId) { List<BackBook> list=new ArrayList<BackBook>(); String sql = "SELECT A.bookid, A.bookname, A.bookstylenumber, B.borrowdate, B.backDate, C.readerid, C.reader_name FROM system_books A INNER JOIN borrow_record B ON A.bookid = B.bookid INNER JOIN system_readers C ON B.readerid = C.readerid WHERE (C.readerid = '"+readerId+"' and A.isborrowed=1)"; Connection conn = null; try { conn = DbHelper.getConnection(); ResultSet re = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE).executeQuery(sql); while(re.next()) { BackBook backBook = new BackBook(); backBook.setBookId(re.getString("bookid")); backBook.setBookName(re.getString("bookname")); backBook.setTypeId(re.getString("bookstylenumber")); backBook.setReaderId(re.getString("readerid")); backBook.setReaderName(re.getString("reader_name")); backBook.setBorrowDate(re.getString("borrowdate")); backBook.setReturnDate(re.getString("backDate")); list.add(backBook); } } catch (SQLException e) { e.printStackTrace(); DbHelper.close(conn); JOptionPane.showMessageDialog(null, "异常:请检查数据是否有误!"); } DbHelper.close(conn); return list; } //图书归还 public static int updateBookBack(String readerId, String readerName, String bookId, String bookName, String bookFee, String borrowDate, String returnDate) { int i = 0; String sql1 = "insert into return_record(bookid,readerid,returndate)values('"+bookId+"','"+readerId+"','"+returnDate+"')"; String sql2 = "insert into reader_fee(readerid,readername,bookid,bookname,bookfee,borrowdate)values('"+readerId+"','"+readerName+"','"+bookId+"','"+bookName+"','"+bookFee+"','"+borrowDate+"')"; Connection conn = null; try { conn = DbHelper.getConnection(); int x = conn.createStatement().executeUpdate(sql1); int y = conn.createStatement().executeUpdate(sql2); if(x == 1 && y == 1) { i = 1; } } catch (SQLException e) { e.printStackTrace(); DbHelper.close(conn); JOptionPane.showMessageDialog(null, "异常:请检查数据是否有误!"); } DbHelper.close(conn); return i; } }
最近下载更多
akittyboy LV9
3月22日
就在这一秒定格 LV7
2023年12月19日
huangzy LV12
2023年6月7日
CL200228 LV4
2023年4月15日
微信网友_5992582549164032 LV6
2023年2月21日
zdmxjxj LV9
2022年12月24日
DeFywOo LV4
2022年12月19日
yuanchuang LV22
2022年10月21日
yangxb2 LV10
2022年9月30日
13112360 LV2
2022年9月20日
最近浏览更多
DEFNXKJ LV2
前天
周青松 LV3
3月28日
朱俪的邮件及存储 LV8
3月26日
akittyboy LV9
3月22日
Dominick LV14
3月20日
周青松197 LV2
3月12日
renyong LV3
3月1日
duoduo1234 LV2
1月15日
3608478377
1月5日
暂无贡献等级
haozhilang LV8
1月3日