New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-issuemaster opened this Issue Jun 3, 2008 · 5 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Jun 3, 2008

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Jun 4, 2008

Juergen Hoeller commented

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

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 17, 2008

Juergen Hoeller commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Dec 11, 2008

Richard Kettelerij commented

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?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Apr 20, 2012

Greg Lloyd commented

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

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Sep 22, 2015

Juergen Hoeller commented

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment