[SPR-4886] Problem extracting Oracle Timestamp with SQLRowset Created: 03/Jun/08  Updated: 15/Jan/19  Resolved: 22/Sep/15

Status: Resolved
Project: Spring Framework
Component/s: None
Affects Version/s: 2.5.3
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Roberto Ruiz Assignee: Juergen Hoeller
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Days since last comment: 9 weeks, 4 days ago
Last commented by a User: true
Last updater: Spring Issuemaster


I extract data from an Oracle Database using org.springframework.jdbc.core.JdbcTemplate.

If I try to extract data from timestamp columns, I get a ClassCastException, because the template gets an oracle.sql.TIMESTAMP object instead of a java.sql.Timestamp.

SqlRowSet rs = _jdbcTemplate.queryForRowSet("SELECT FFNACPER FROM TEMP_ALPER");
java.sql.Timestamp timestamp = rs.getTimestamp("FFNACPER"); //HERE I GET A CLASSCASTEXCEPTION

To make it work, I must get an object, and convert it manually:

oracle.sql.TIMESTAMP timestamp = (oracle.sql.TIMESTAMP) rs.getObject("FFNACPER");
return (timestamp == null) ? null : new Date(timestamp.dateValue().getTime());

It also works ok, if I use a ResultSetExtractor instead of an SqlRowSet

_jdbcTemplate.query("SELECT FFNACPER FROM TEMP_ALPER", new ResultSetExtractor(){
public Object extractData(ResultSet rs) throws SQLException, DataAccessException

{ rs.next(); Timestamp t = rs.getTimestamp("FFNACPER"); //WORKS OK return t; }

} );

Have tested only for timestamp. Haven't tried with rs.getDate, or rs.getTime

Comment by Juergen Hoeller [ 04/Jun/08 ]

The bug is probably in Sun's CachedRowSetImpl class here. Not sure what we can do about this...


Comment by Juergen Hoeller [ 17/Sep/08 ]

Even if this is fundamentally a limitation of Sun's JDBC RowSet implementation, we'll see whether can work around it in Spring 3.0.


Comment by Richard Kettelerij [ 11/Dec/08 ]

I'm facing a similair issue. In my case the exception is thrown from queryForRowSet(), instead of the getTimestamp() method.

The exception says "Invalid SQL type for column". This due to the timestamp column in my table which is defined as "TIMESTAMP(6) WITH LOCAL TIME". The "with local time" part isn't recognized as a valid type by Sun's CachedRowSetImpl. Perhaps this can also be taken into account when fixing (or working around) this issue in Spring 3.0?

Comment by Greg Lloyd [ 20/Apr/12 ]

Any chance this is going to get moved out of the backlog anytime soon?

Comment by Juergen Hoeller [ 22/Sep/15 ]

Closing groups of outdated issues. Please reopen if still relevant.

Comment by Spring Issuemaster [ 14/Jan/19 ]

The Spring Framework has migrated to GitHub Issues. This issue corresponds to spring-projects/spring-framework#9562.

Generated at Sat Mar 23 20:37:56 UTC 2019 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.