简体   繁体   English

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

[英]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.

相关问题 为什么 java.sql.Timestamp 在 1970-01-01 之后返回负值 - why java.sql.Timestamp return negative value when the date is after 1970-01-01 如何正确地将新的Date(0L)转换为LocalDate(1970-01-01)? - How to properly convert new Date(0L) to LocalDate (1970-01-01)? JMeter:Sampler结果显示“ Sample Start:1970-01-01 05:30:00 IST” - JMeter: Sampler results shows “Sample Start: 1970-01-01 05:30:00 IST” 如何从Java中的纪元(1970-01-01)获得毫秒? - How do I get milliseconds from epoch (1970-01-01) in Java? 将完整的Java日期(例如,2013年6月19日上午8.00)转换为一个时间(即1970-01-01上午8.00) - Convert a full Java date (e.g. 8.00am 2013-06-19) to just a time (i.e. 8.00am 1970-01-01) 数据类型为日期时间的列的值在 Java 中始终为 1970/01/01 - The value of the column with data type of datetime always is 1970/01/01 in Java 为什么java.sql.Date.getTime()对于1970-01-02返回82_800_000而不是86_400_000? - Why does java.sql.Date.getTime() returns 82_800_000 for 1970-01-02 instead of 86_400_000? oracle:如何将类似“ 2000-01-01T01:01:01”的字符串转换为Date? - oracle: how to convert string like '2000-01-01T01:01:01' to Date? 用jodatime解析日期01-01-0001 - parsing date 01-01-0001 with jodatime 获取:使用MySQL列中的JDBC输出1970年1月1日 - Getting :Jan 01, 1970 output with JDBC from MySQL columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM