queryForRowSet cant return full datetime precision

Assuming you are using Oracle here since this looks like a known issue with the 10g JDBC driver.

The 10g driver reports DATE columns as Timestamp in the metadata but if you do a getObject() you get a java.sql.Date. Oracle claims you should use the TIMESTAMP datatype instead if you want the time portion. Drawback here is that getObject() returns an oracle.sql.TIMESTAMP which does not extend any of the standard JDBC classes. To work around this you would have to do something like this:


SqlRowSet rset = jdbcTemplate.queryForRowSet(
"select cast(sysdate as timestamp) from dual");
try {
    while (rset.next()) {
    System.out.println("-> " +
         ((oracle.sql.TIMESTAMP)rset.getObject(1)).timestam pValue());
}
} catch (SQLException e) {
     e.printStackTrace();
}

We have a workaround for this in the queryForList methods but for queryForRowSet we depend on Sun's RowSet implementation to extract the data from the original ResultSet.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值