private void testDatetimeWithCalendar() throws SQLException {
trace("Test DATETIME with Calendar");
ResultSet rs;
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, D DATE, T TIME, TS TIMESTAMP)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?, ?)");
Calendar regular = Calendar.getInstance();
Calendar other = null;
// search a locale that has a _different_ raw offset
long testTime = java.sql.Date.valueOf("2001-02-03").getTime();
for (String s : TimeZone.getAvailableIDs()) {
TimeZone zone = TimeZone.getTimeZone(s);
long rawOffsetDiff = regular.getTimeZone().getRawOffset() - zone.getRawOffset();
// must not be the same timezone (not 0 h and not 24 h difference
// as for Pacific/Auckland and Etc/GMT+12)
if (rawOffsetDiff != 0 && rawOffsetDiff != 1000 * 60 * 60 * 24) {
if (regular.getTimeZone().getOffset(testTime) != zone.getOffset(testTime)) {
other = Calendar.getInstance(zone);
break;
}
}
}
trace("regular offset = " + regular.getTimeZone().getRawOffset() + " other = "
+ other.getTimeZone().getRawOffset());
prep.setInt(1, 0);
prep.setDate(2, null, regular);
prep.setTime(3, null, regular);
prep.setTimestamp(4, null, regular);
prep.execute();
prep.setInt(1, 1);
prep.setDate(2, null, other);
prep.setTime(3, null, other);
prep.setTimestamp(4, null, other);
prep.execute();
prep.setInt(1, 2);
prep.setDate(2, java.sql.Date.valueOf("2001-02-03"), regular);
prep.setTime(3, java.sql.Time.valueOf("04:05:06"), regular);
prep.setTimestamp(4, java.sql.Timestamp.valueOf("2007-08-09 10:11:12.131415"), regular);
prep.execute();
prep.setInt(1, 3);
prep.setDate(2, java.sql.Date.valueOf("2101-02-03"), other);
prep.setTime(3, java.sql.Time.valueOf("14:05:06"), other);
prep.setTimestamp(4, java.sql.Timestamp.valueOf("2107-08-09 10:11:12.131415"), other);
prep.execute();
prep.setInt(1, 4);
prep.setDate(2, java.sql.Date.valueOf("2101-02-03"));
prep.setTime(3, java.sql.Time.valueOf("14:05:06"));
prep.setTimestamp(4, java.sql.Timestamp.valueOf("2107-08-09 10:11:12.131415"));
prep.execute();
rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
assertResultSetMeta(rs, 4,
new String[] { "ID", "D", "T", "TS" },
new int[] { Types.INTEGER, Types.DATE, Types.TIME, Types.TIMESTAMP },