googleapis / java-spanner-jdbc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support LocalDateTime & OffsetDateTime

skairunner opened this issue · comments

Is your feature request related to a problem? Please describe.
There is currently no way to get a LocalDateTime or OffsetDateTime from the Spanner jdbc client. Because java.sql.Timestamp is affected by the local jvm's timezone, it is known to have issues with representing TIMESTAMP WITHOUT TIMEZONE and has the possibility of silently converting it to a different timezone. My understanding is that it is now best practice to use java.time classes instead.

Describe the solution you'd like
Add LocalDateTime and OffsetDateTime support to the getObject and setObject methods on ResultSet.

Describe alternatives you've considered
It is possible to use java.sql.Timestamp, but care must be used to prevent inadvertently converting between timezones.

@skairunner Cloud Spanner only supports TIMESTAMP [WITH TIME ZONE]. There is no type without timezone information that is supported. That is why LocalDateTime is not supported in the JDBC driver.

OffsetDateTime is already supported. So the following calls are valid and supported:

ResultSet#getObject(1, OffsetDateTime.class);
PreparedStatement#setObject(1, OffsetDateTime.now());

Closing as the driver seems to support what is being requested here (and does not support anything like timestamp without time zone). Please feel free to reopen if I've missed anything.