Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SQLite';介于'之间;不';I don’我没有表现得像预期的那样_Java_Sqlite_Jdbc - Fatal编程技术网

Java SQLite';介于'之间;不';I don’我没有表现得像预期的那样

Java SQLite';介于'之间;不';I don’我没有表现得像预期的那样,java,sqlite,jdbc,Java,Sqlite,Jdbc,我试图选择两列值之间的所有行。这些值是UNIX时间戳,但查询根本不返回任何行。为什么会这样 这是我的密码: public static ArrayList<Appointment> getAppointments(long start, long end) { ArrayList<Appointment> appointments = new ArrayList<>(); try { Statement stat = db.cr

我试图选择两列值之间的所有行。这些值是UNIX时间戳,但查询根本不返回任何行。为什么会这样

这是我的密码:

public static ArrayList<Appointment> getAppointments(long start, long end) {
    ArrayList<Appointment> appointments = new ArrayList<>();
    try {
        Statement stat = db.createStatement();
        System.out.println("\n" + start + "  ->  " + end);

        // debugging only
        try (ResultSet rs = stat.executeQuery("SELECT * FROM appointments;")) {
            while (rs.next()) {
                long time = rs.getLong("date");
                if (time >= start && time <= end) {
                    System.out.println("Should be adding to list");
                }
            }
        } // 

        try (ResultSet rs = stat.executeQuery("SELECT * FROM appointments WHERE date BETWEEN " + start + " AND " + end + ";")) {
            while (rs.next()) {
                System.out.println("ADDING");
                appointments.add(new Appointment(rs.getLong("date"), rs.getInt("duration")));
            }
        }
    } catch (SQLException ex) {
    }
    System.out.println(appointments);
    return appointments;
}
输出为:

date = 1347390000000 duration = 15
date = 1347461100000 duration = 30
date = 1347469200000 duration = 45

1350141222283  ->  1350746022283
[]

1349536422283  ->  1350141222283
[]

1348931622283  ->  1349536422283
[]

1348330422283  ->  1348931622283
[]

1347725622283  ->  1348330422283
[]

1347120822283  ->  1347725622283
Should be adding to list
Should be adding to list
Should be adding to list
[]

1346516022283  ->  1347120822283
[]

您必须声明列的数据类型。

您在盲目地捕获SQLExceptions。不要那样做。放一些至少报告它们是什么的代码。我省略了catch代码,因为它与问题无关。至于输出,据我所知,它是完全合理的。[]是每次搜索范围更改时(每周)该方法返回的内容。+1回到问题,我不确定发生了什么,因为查询在SQL FIDLE上工作。现在一切都是System.out,因为out和err不同步,这就是顺序混乱的原因。对此表示歉意有趣的是,它在SQL Fiddle上工作,我觉得这是我在某个地方遗漏的一个小细节。也许“日期”列在数据库中没有定义得那么长?这可能会导致意外行为。
date = 1347390000000 duration = 15
date = 1347461100000 duration = 30
date = 1347469200000 duration = 45

1350141222283  ->  1350746022283
[]

1349536422283  ->  1350141222283
[]

1348931622283  ->  1349536422283
[]

1348330422283  ->  1348931622283
[]

1347725622283  ->  1348330422283
[]

1347120822283  ->  1347725622283
Should be adding to list
Should be adding to list
Should be adding to list
[]

1346516022283  ->  1347120822283
[]