0

这是我的尝试:

rs = statement.executeQuery("select * from geninfo where DeviceTag='" + deviceTag + "' and timestamp='date('"+fromYear + "-" +fromMonth + "-" + fromDay + "')';");

它看起来类似于:

select * from geninfo where timestamp='date('2013-07-08')';

错误是(near "2013": syntax error)

存储的值为“2013-07-08 09:08:51”

我想选择某一天的所有数据。另外,将另一列存储为日期对象会更容易吗?

4

1 回答 1

0
  1. 不能date用单引号将函数括起来,单引号是字符串分隔符。您在 SQL 语句中拥有的是字符串date(、数字20130708,它们彼此相减,以及字符串)
  2. 该函数date将字符串2013-07-08转换为字符串2013-07-08。将其与字符串进行比较2013-07-08 09:08:51将失败。您想从具有时间字段的字符串中去除时间:

    SELECT *
    FROM geninfo
    WHERE DeviceTag = ?
      AND date(timestamp) = '2013-07-08'
    
于 2013-07-08T16:34:39.633 回答