我正在编写一个Java桌面应用程序。这段代码用于与我的模拟数据库一起使用。现在它返回1970-01-01
作为系统日期。我正在使用eclipse。请帮忙。
JButton btnCheckAvailability = new JButton("Check Availability");
btnCheckAvailability.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int count=0;
String q="Select * from IssueLog where Book_id= ?";
try{
PreparedStatement p=con.prepareStatement(q);
p.setString(1,bid);
ResultSet rst=p.executeQuery();
while(rst.next()){
count++;
String q2 ="select date('now')";
PreparedStatement pst5 = con.prepareStatement(q2);
ResultSet rs55 = pst5.executeQuery();
//JOptionPane.showMessageDialog(null,rs55.getDate(1));
if((rs55.getDate(1)).before(rst.getDate("Due_Date"))){
String qw="Select Name from Members where Id_no=?";
PreparedStatement pst0=con.prepareStatement(qw);
pst0.setString(1, rst.getString("id_no"));
ResultSet r = pst0.executeQuery();
JOptionPane.showMessageDialog(null,"It is currently with "+r.getString("Name")+"\nCome back after "+rst.getString("Due_Date"));
pst5.close();
pst0.close();
rs55.close();
r.close();
}
else
JOptionPane.showMessageDialog(null, "Available");
}
rst.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(count!=1)
JOptionPane.showMessageDialog(null, "Available");
}
});
答案 0 :(得分:0)
我仍然不知道这是怎么发生的。 但这是有效的。
String q2 ="select date('now')";
PreparedStatement pst5 = con.prepareStatement(q2);
ResultSet rs55 = pst5.executeQuery();
//JOptionPane.showMessageDialog(null,rs55.getString(1));
if(rs55.getString(1).compareTo(rst.getString("Due_Date"))>0){
答案 1 :(得分:-1)
尝试使用select NOW()
代替select date('now')
。我猜你在你的查询中得到null,然后当你调用rs55.getDate(1)时,你会得到一个Date对象,该对象从epoch开始构造为0毫秒,即1970-01-01 00:00:00。