真心求解、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