Converting between Instant and Timestamp in JDBC is causing the time to drift by the difference between the system timezone and UTC.
When setting an Instant
to a TIMESTAMP
field in JDBC, do this to prevent the time from drifting by the difference between your system timezone and UTC.
preparedStatement.setTimestamp(
place,
Timestamp.valueOf(
LocalDateTime.ofInstant(
param.toJavaInstant(),
ZoneId.of(Calendar.getInstance().timeZone.id)
)
)
)
No care needs to be taken when retrieving the TIMESTAMP because it comes with a TZ that the Instant accounts for.