[英]Why is my SQLite query returning the system date as 1970-01-01?
I'm writing a Java desktop application.我正在编写一个 Java 桌面应用程序。 This code used to work fine with my mock database.这段代码曾经在我的模拟数据库中工作得很好。 Now it is returning 1970-01-01
as system date.I'm using eclipse.现在它返回1970-01-01
作为系统日期。我正在使用 eclipse。 Please help.请帮忙。
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");
}
});
I still don't know how this happened.我仍然不知道这是怎么发生的。 But here's what worked.但这是有效的。
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){
Try using select NOW()
instead of select date('now')
.尝试使用select NOW()
而不是select date('now')
。 I guess you get null in your query and then when you call rs55.getDate(1) you get a Date object that is constructed as 0 milliseconds from epoch which is 1970-01-01 00:00:00.我猜你在查询中得到空值,然后当你调用 rs55.getDate(1) 时,你会得到一个 Date 对象,它从 1970-01-01 00:00:00 的纪元开始构造为 0 毫秒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.