我正在进行一项查询,其中有两列来自不同的数据库,用于存储带时间戳的日期。稍后我运行以下查询以获得整数小时。
SELECT tab1.col1,
tab1.date1 as d1, tab2.date2 as d2,
(EXTRACT(EPOCH FROM tab2.date2 - tab1.date1)/3600)::integer as delta
FROM table1 tab1 left join table2 tab2 on tab1.col1=tab2.col1;
其中,
date1 have following value= "2014-03-22 22:00:00.022023"
and date2 = "2014-03-26 16:45:04.445531"
当上述查询运行时,将其返回为delta
= 91小时
我需要使用Java进行此计算,
到目前为止,我做了什么:
String sql3 = " Select col1, date1 from table2 where col1 =?";
for (QueryResponse resp : response) {
statement3 = connection3.prepareStatement(sql3);
statement3.setString(1, resp.getCol1());
Timestamp queryDate = resp.getqDate();
// execute select SQL stetement
ResultSet rs3 = statement3.executeQuery();
while (rs3.next()) {
String col = rs3.getString("col1");
Timestamp createdDate = rs3.getTimestamp("date1");
int delta = 48; // Not sure how to calculate
resp.setDelta(delta);
}
同样地,我在response
我想执行相同的
(EXTRACT(EPOCH FROM tab2.date2 - tab1.date1)/3600)::integer as delta
在用java编写int delta = 48
的块中?
对此的任何帮助都会很棒,我不知道如何在Java中转换它Epoch
功能