日期:2014-05-17 浏览次数:20592 次
public int insertBorrow(ReaderForm readerForm, BookForm bookForm,String operator) {
// 获取系统日期
Calendar cal = Calendar.getInstance();
Date date0 = cal.getTime();
java.sql.Date date = new java.sql.Date(date0.getTime());
// 查询该书本可借天数
String sql1 = "select t.days from tb_bookinfo b left join tb_booktype t on b.typeid=t.id where b.id="+ bookForm.getId() + "";
ResultSet rs = conn.executeQuery(sql1);
int days = 0; //days的初始值
int flag = 0;
try {
if (rs.next()) {
days = (int)rs.getInt(3);
//表中的第三列便是书本的可借天数,假设该类的书的可借天书为30天。那days=30;
//问题出在这里,这里获取的days值传递不出去。
}
} catch (SQLException ex) {
}
//计算归还时间
cal.add(Calendar.DAY_OF_MONTH, days);
//不知道为什么,这里的days永远等于days的初始值,即days!=30而是days=0;
Date date1 = cal.getTime();
java.sql.Date backTime = new java.sql.Date(date1.getTime());
String sql = "Insert into tb_borrow (readerid,bookid,borrowTime,backTime,operator) values("
+ readerForm.getId()
+ ","
+ bookForm.getId()
+ ",'"
+ date + "','" + backTime + "','" + operator + "')";
flag = conn.executeUpdate(sql);
System.out.println("添加图书借阅信息的SQL:" + sql);
conn.close();
return flag;
}
//计算归还时间
cal.add(Calendar.DAY_OF_MONTH, days);
//不知道为什么,这里的days永远等于days的初始值,即days!=30而是days=0;
Date date1 = cal.getTime();
java.sql.Date backTime = new java.sql.Date(date1.getTime());
String sql = "Insert into tb_borrow (readerid,bookid,borrowTime,backTime,operator) values("
+ readerForm.getId()
+ ","
+ bookForm.getId()
+ ",'"
+ date + "','" + backTime + "','" + operator + "')";
flag = conn.executeUpdate(sql);
System.out.println("添加图书借阅信息的SQL:" + sql);
package com.test;
public class Sb {
public static void main(String[] arg