即使查询有效,ResultSet也为空

时间:2014-12-22 22:46:03

标签: java sqlite jdbc prepared-statement resultset

我有以下代码:

StringBuilder queryBuilder = new StringBuilder();
queryBuilder.append("SELECT * FROM EVENTS WHERE ((EVENT_DATE BETWEEN ? AND ?) AND (EVENT_TIME BETWEEN ? AND ?))");
connection = SQLiteWrapper.getConnection();
            try (PreparedStatement pst = connection.prepareStatement(queryBuilder.toString()))
            {
                calendar = Calendar.getInstance();
                Calendar copy = (Calendar) calendar.clone();
                copy.set(1900, 0, 1);
                SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                String formattedStartDate = dateFormat.format(calendar.getTime());
                String formattedStartTime = timeFormat.format(copy.getTime());
                copy.add(Calendar.HOUR_OF_DAY, 12);
                calendar.add(Calendar.HOUR_OF_DAY, 12);
                String formattedEndDate = dateFormat.format(calendar.getTime());
                String formattedEndTime = timeFormat.format(copy.getTime());
                pst.setDate(1, java.sql.Date.valueOf(formattedStartDate));
                pst.setDate(2, java.sql.Date.valueOf(formattedEndDate));
                pst.setTimestamp(3, Timestamp.valueOf(formattedStartTime));
                pst.setTimestamp(4, Timestamp.valueOf(formattedEndTime));

稍后,我执行准备好的语句,如下所示:ResultSet set = pst.executeQuery()

由于某些未知原因,此查询在实际应该选择时不会选择任何内容 - 如果我在SQLite的查询编辑器中执行它,它就会起作用。

有原因吗?我做错了吗?

0 个答案:

没有答案