-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
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