我收到此错误,但我不明白为什么我在工作台上尝试了该语句并且它起作用了。我也在寻找改进我的日期减去代码基本上我从表格中得到最后期限,我正在从今天的日期中减去。
public boolean checkLessThanWeek(User userWhoWantsToExtendDeadline,BorrowedBook book) throws ParseException {
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Deadline FROM library_students.borrowedcopies WHERE LenderToID =" + "'" + userWhoWantsToExtendDeadline.getId()+ "'"+"And Barcode="+"."+book.getbookID());
if (rs.next()) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
Date deadline = format.parse(rs.getString(1));
Date date=new Date();
String today=format.format(date.getDate());
date = format.parse(today);
long milliseconds=date.getTime()-deadline.getTime();
long days = milliseconds / (1000 * 60 * 60 * 24);
System.out.print(days);
}
rs.close();
return true;
} catch (SQLException ex) {
ex.printStackTrace();
return false;
}
}
叮当猫咪
相关分类