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.
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.
针对Oracle 10g JDBC驱动中DATE类型被错误报告为Timestamp的问题进行了解析,并提供了一种解决方案,通过使用getObject()方法并转换为标准的java.sql.Timestamp来解决此问题。
631

被折叠的 条评论
为什么被折叠?



