2016-08-15 25 views
0
Query query = session.createSQLQuery("SELECT ((extract (epoch from (end_time::timestamp - start_time::timestamp))))::integer from Trip_Details where td_id = "+transacId+" "); 

在Postgres的SQL 2个时间戳之间的区别我想这个查询来获取之间的两个时间戳即START_TIME,stop_time的差异中。如何获得Java中

但得到例外下面

ERROR: stderr - org.hibernate.QueryException: Not all named parameters have been set: [:timestamp, :integer] [SELECT ((extract (epoch from (end_time::timestamp - start_time::timestamp))))::integer from Trip_Details where td_id = 1 ] 

及其postgres的PG的管理控制台上工作正常和获得输出如在整数格式202秒。

请帮我找出错误并解决它。 在此先感谢

+0

可你'查询查询=执行Session.createSQLQuery(“SELECT((提取物(从(END_TIME ::时间戳时代 - start_time :: timestamp)))):: Trip_Details中的整数,其中td_id ='+ transacId +'');'in Java?.. –

回答

0

我怀疑双引号治疗你不好。 Java之前的冒号用于设置变量。我认为,如果你改变你的代码:

Query query = session.createSQLQuery("SELECT cast((extract (epoch from (cast(end_time as timestamp)- cast(start_time as timestamp)))) AS integer) from Trip_Details where td_id = "+transacId+" "); 

应该开始工作......