Skip to content

JdbcTemplate should support JDBC 4.1 getObject(columnIndex, type) [SPR-11600] #16223

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 3fef358, 3767938, c9432ce

Metadata

Metadata

Assignees

Labels

in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions