Java 为什么我的SQLite查询返回系统日期为1970-01-01?

Java 为什么我的SQLite查询返回系统日期为1970-01-01?,java,eclipse,sqlite,Java,Eclipse,Sqlite,我正在编写一个Java桌面应用程序。这段代码过去可以很好地处理我的模拟数据库。现在它将1970-01-01作为系统日期返回。我正在使用eclipse。请帮忙 JButton btnCheckAvailability = new JButton("Check Availability"); btnCheckAvailability.addActionListener(new ActionListener() { public void ac

我正在编写一个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");

                }

            });

尝试使用
select NOW()
而不是
select date('NOW')
。我猜您在查询中会得到null,然后当您调用rs55.getDate(1)时,您会得到一个Date对象,它是从1970-01-01 00:00:00的历元开始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){

这是计算时间的起始日期。如果用0毫秒构造date对象,您就会得到它。不同的数据库在使用日期和时间方面有不同的习惯用法。一些数据库可能会使用
date('now')
,其他数据库可能会使用
now()
,其他数据库可能会使用
current\u date
等等。这会导致错误。缺少数据库或没有这样的列。为什么不将该日期作为new Date()获取呢。我看不出使用查询的原因。