Getting the date from a ResultSet for use with java.time classes

Most database vendors don’t support JDBC 4.2 yet. This specification says that the new java.time-types like LocalDate will/should be supported using the existing methods setObject(...) and getObject(). No explicit conversion is required and offered (no API-change).

A workaround for the missing support can be manual conversion as described on the Derby-mailing list.

Something like:

LocalDate birthDate = resultSet.getDate("birth_date").toLocalDate();

As you can see, these conversions use the non-deprecated types java.sql.Date etc., see also the javadoc.

Leave a Comment