Description
Philippe Marschall opened SPR-11600 and commented
JDBC 4.2 defines the following type mappings
ANSI SQL | Java SE 8 |
---|---|
DATE | LocalDate |
TIME | LocalTime |
TIMESTAMP | LocalDateTime |
TIME WITH TIMEZONE | OffsetTime |
TIMESTAMP WITH TIMEZONE | OffsetDateTime |
with can be used through ResultSet#getObject(int, Class)
, ResultSet#getObject(String, Class)
,PreparedStatement#setObject(int, Object)
So I would expect the following to work
jdbcTemplate.queryForObject("SELECT DATE_COLUMN FROM JAVA_TIME", LocalDate.class);
but it doesn't, it fails with:
org.springframework.dao.TypeMismatchDataAccessException: Type mismatch affecting row number 0 and column type 'DATE': Value [1988-12-25] is of type [java.sql.Date] and cannot be converted to required type [java.time.LocalDate]
Instead I have to do
jdbcTemplate.queryForObject("SELECT DATE_COLUMN FROM JAVA_TIME",
(rs, rowNum) -> rs.getObject(1, LocalDate.class));
The issue seems to be that JdbcUtils.getResultSetValue(ResultSet, int, Class<?>)
calls JdbcUtils.getResultSetValue(ResultSet, int)
without the required type. I don't know if this an oversight or intentional.
Affects: 4.0.2
Issue Links:
- 'Invalid column type' exception generated when writing a Boolean data member to Oracle database [SPR-14581] #19150 'Invalid column type' exception generated when writing a Boolean data member to Oracle database
- Java boolean is not handled correctly when used with Oracle JDBC driver [SPR-14116] #18688 Java boolean is not handled correctly when used with Oracle JDBC driver
- Can't insert into nvarchar2 using SimpleJdbcInsert whereas it works with SimpleJdbcTemplate [SPR-8571] #13215 Can't insert into nvarchar2 using SimpleJdbcInsert whereas it works with SimpleJdbcTemplate