Skip to content

Problem extracting Oracle Timestamp with SQLRowset [SPR-4886] #9562

@spring-projects-issues

Description

@spring-projects-issues

Roberto Ruiz opened SPR-4886 and commented

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


Affects: 2.5.3

1 votes, 2 watchers

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions