`
carrot
  • 浏览: 163078 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics