• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

真心求解、postgresql数据库使用between and的有关问题。

mysql 搞代码 7年前 (2018-06-04) 196次浏览 已收录 0个评论

真心求解、postgresql数据库使用between and的问题。。
select sum(tc."TYPE0"),sum(tc."TYPE1"),sum(tc."TYPE2") 
from "IVM_Temp"."TBL_COUNTING_2012_6_26" as tc,"IVM_Temp"."TBL_CHANNEL" as tl 
where tc."CHANNELID" = tl."CHANNEL_ID" 
and tl."IPCAM_IPADDRESS" = ‘192.168.7.101’
and tc."ENDDATETIME" between ‘2012-05-12 14:35:00’ and ‘2012-08-12 14:35:00’;

SQL是这样写的。。在数据库里已通过。。

但是。。

java jdbc写的时候。

加上between ? and ? 就报错误。。如下。

org.postgresql.util.PSQLException: ERROR: operator does not exist: timestamp without time zone >= character varying
  建议:No operator matches the given name and argument type(s). You might need to add explicit type casts.

部分jdbc如下。
String sql = "select sum(tc./"TYPE0/"),sum(tc./"TYPE1/"),sum(tc./"TYPE2/") " +
"from /"IVM_Temp/"./"TBL_COUNTING_2012_6_26/" as tc,/"IVM_Temp/"./"TBL_CHANNEL/" as tl " +
"where tc./"CHANNELID/" = tl./"CHANNEL_ID/" " +
"and tl./"IPCAM_IPADDRESS/" = ?" +
" and tc./"ENDDATETIME/" between ? and ? ";
conn = ConnectionPostgresql.getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, ip);
ps.setString(2, begin);
ps.setString(3, end);
rs = ps.executeQuery();
while(rs.next())
{
test = new Test();
test.setTYPE0(rs.getLong(1));
test.setTYPE1(rs.getLong(2));
test.setTYPE2(rs.getLong(3));
}

就是between and 出问题。。用>和<也不行。。求解。。

——解决方案——————–
2和3,言用setTimeStamp,不要用setString


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:真心求解、postgresql数据库使用between and的有关问题。

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址