Hi,
java.util.Date automatically converts such times (forward or backward
one hour across DST boundaries). I know this is a problem because
normally, you don't want this "feature". For timezone that have the
DST boundaries at midnight it's really big problem because it can
affect the day (when using java.sql.Date). The problem is that the
times are 'equal' even before they are going into the database:
TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
Timestamp a = new Timestamp(1162080120000l);
Timestamp b = new Timestamp(1162083720000l);
System.out.println(a);
System.out.println(b);
Output:
2006-10-29 02:02:00.0
2006-10-29 02:02:00.0
If you insert the values as strings, then no conversion occurs,
because H2 doesn't use java.util.Date and Calendar internally (for
exactly that reason: to avoid problems caused by java.util.Date).
Regards,
Thomas
On Fri, Jul 20, 2012 at 4:19 PM, Maarten Donders
<[email protected]> wrote:
> On an attempt to insert unique dates crossing a DST boundary I receive
> a wrong unique constraint violation.
>
> Here is a test case to insert into the TestDataStorage class:
>
> private void testDST() throws SQLException {
> Connection conn = getConnection("date");
> Statement stat = conn.createStatement();
> TimeZone defaultTimeZone = TimeZone.getDefault();
> stat.execute("create table test(ts timestamp primary key)");
> try {
>
> TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
> Calendar calendar = new
> GregorianCalendar(TimeZone.getDefault());
>
> PreparedStatement prep = conn
> .prepareStatement("INSERT INTO TEST
> VALUES(?)");
> prep.setTimestamp(1, new
> java.sql.Timestamp(1162080120000l),
> calendar);
> prep.execute();
> prep.setTimestamp(1, new
> java.sql.Timestamp(1162083720000l),
> calendar);
> prep.execute();
> } finally {
> TimeZone.setDefault(defaultTimeZone);
> DateTimeUtils.resetCalendar();
> }
> conn.close();
> deleteDb("date");
> }
>
> --
> You received this message because you are subscribed to the Google Groups "H2
> Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/h2-database?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.