|
37 | 37 | import java.sql.ResultSet; |
38 | 38 | import java.sql.SQLException; |
39 | 39 | import java.sql.Types; |
| 40 | +import java.util.Calendar; |
| 41 | +import java.util.Date; |
| 42 | +import java.util.GregorianCalendar; |
40 | 43 | import java.util.Hashtable; |
41 | 44 | import java.util.List; |
42 | 45 | import java.util.Objects; |
| 46 | +import java.util.TimeZone; |
43 | 47 | import javax.annotation.Nullable; |
44 | 48 | import javax.management.InstanceNotFoundException; |
45 | 49 | import javax.management.IntrospectionException; |
|
55 | 59 | public final class DBUtils { |
56 | 60 | private static final Logger LOG = LoggerFactory.getLogger(DBUtils.class); |
57 | 61 |
|
| 62 | + private static final Calendar PURE_GREGORIAN_CALENDAR = createPureGregorianCalender(); |
| 63 | + |
| 64 | + // Java by default uses October 15, 1582 as a Gregorian cut over date. |
| 65 | + // Any timestamp created with time less than this cut over date is treated as Julian date. |
| 66 | + // This causes old dates from database such as 0001-01-01 01:00:00 mapped to 0000-12-30 |
| 67 | + // Get the pure gregorian calendar so that all dates are treated as gregorian format. |
| 68 | + private static Calendar createPureGregorianCalender() { |
| 69 | + GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("UTC")); |
| 70 | + gc.setGregorianChange(new Date(Long.MIN_VALUE)); |
| 71 | + return gc; |
| 72 | + } |
| 73 | + |
58 | 74 | /** |
59 | 75 | * Performs any Database related cleanup |
60 | 76 | * |
@@ -116,7 +132,7 @@ public static Object transformValue(int sqlType, int precision, int scale, |
116 | 132 | case Types.TIME: |
117 | 133 | return resultSet.getTime(columnIndex); |
118 | 134 | case Types.TIMESTAMP: |
119 | | - return resultSet.getTimestamp(columnIndex); |
| 135 | + return resultSet.getTimestamp(columnIndex, PURE_GREGORIAN_CALENDAR); |
120 | 136 | case Types.ROWID: |
121 | 137 | return resultSet.getString(columnIndex); |
122 | 138 | case Types.BLOB: |
|
0 commit comments