Tell JDBC to use UTC when converting timestamp.

This is apparently the recommended thing to do, but JDBC & SQL handling of
TIMESTAMP and java.sql.Timestamp are pretty abysmal.
This commit is contained in:
Michael Bayne
2026-04-18 17:05:25 -07:00
parent bbed6b1fe2
commit 54afc8490a
@@ -8,6 +8,8 @@ package com.samskivert.jdbc.jora;
import java.sql.*; import java.sql.*;
import java.math.*; import java.math.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.Calendar;
import java.util.TimeZone;
class FieldDescriptor class FieldDescriptor
{ {
@@ -99,7 +101,7 @@ class FieldDescriptor
pstmt.setTime(column, (java.sql.Time)field.get(obj)); pstmt.setTime(column, (java.sql.Time)field.get(obj));
break; break;
case tTimestamp: case tTimestamp:
pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj)); pstmt.setTimestamp(column, (java.sql.Timestamp)field.get(obj), UTC_CALENDAR);
break; break;
case tStream: case tStream:
java.io.InputStream in = (java.io.InputStream)field.get(obj); java.io.InputStream in = (java.io.InputStream)field.get(obj);
@@ -325,7 +327,7 @@ class FieldDescriptor
field.set(obj, result.getTime(column)); field.set(obj, result.getTime(column));
break; break;
case tTimestamp: case tTimestamp:
field.set(obj, result.getTimestamp(column)); field.set(obj, result.getTimestamp(column, UTC_CALENDAR));
break; break;
case tStream: case tStream:
field.set(obj, result.getBinaryStream(column)); field.set(obj, result.getBinaryStream(column));
@@ -417,4 +419,7 @@ class FieldDescriptor
Types.VARCHAR, // tAsString Types.VARCHAR, // tAsString
Types.LONGVARBINARY // tClosure Types.LONGVARBINARY // tClosure
}; };
/** A UTC calendar used to ensure timezone-correct Timestamp binding and loading. */
private static final Calendar UTC_CALENDAR = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
} }