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:
@@ -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"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user