[SPR-4886] Problem extracting Oracle Timestamp with SQLRowset Created: 03/Jun/08  Updated: 22/Sep/15  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: 3 years, 2 days ago
Last commented by a User: false
Last updater: Juergen Hoeller

 Description   

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");
rs.next();
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



 Comments   
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...

Juergen

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.

Juergen

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.

Generated at Thu Sep 20 22:41:54 UTC 2018 using JIRA 7.9.2#79002-sha1:3bb15b68ecd99a30eb364c4c1a393359bcad6278.