Major Date delima, Quick response appreciated

28 views
Skip to first unread message

all...@gmail.com

unread,
Jun 17, 2007, 9:11:52 AM6/17/07
to H2 Database
Hi;

I have a project that I have been working with happily using H2, which
bring me to where I should thank the creator of the project so much
for such wonderful database. today, I was suppose to activate my
project to the users, and I hit a bug, looking around I reached to the
point that one of the inserts caused it, and specifically date parse
in that INSERT, so I tried to see if this problem is a result of the
engine itself, and yes, it is, if I execute the below instructions:

SELECT CAST('2005-3-31' AS DATE);

I get:

SELECT CAST('2005-3-31' AS DATE);
Cannot parse date constant 2005-3-31; SQL statement: SELECT
CAST('2005-3-31' AS DATE) [90009-46]
org.h2.jdbc.JdbcSQLException: Cannot parse date constant 2005-3-31;
SQL statement: SELECT CAST('2005-3-31' AS DATE) [90009-46]
at org.h2.message.Message.addSQL(Message.java:348)
at org.h2.command.Parser.prepareCommand(Parser.java:213)
at org.h2.engine.Session.prepareLocal(Session.java:173)
at org.h2.engine.Session.prepareCommand(Session.java:155)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:
966)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:143)
at org.h2.server.web.AppThread.getResult(AppThread.java:941)
at org.h2.server.web.AppThread.query(AppThread.java:611)
at org.h2.server.web.AppThread.process(AppThread.java:71)
at org.h2.server.web.WebServerThread.run(WebServerThread.java:127)
Caused by: org.h2.jdbc.JdbcSQLException: Cannot parse date constant
2005-3-31 [90009-46]
at org.h2.message.Message.getSQLException(Message.java:65)
at org.h2.message.Message.getSQLException(Message.java:47)
at org.h2.util.DateTimeUtils.parseDateTime(DateTimeUtils.java:217)
at org.h2.value.ValueDate.parseDate(ValueDate.java:27)
at org.h2.value.Value.convertTo(Value.java:474)
at org.h2.expression.Function.getValueWithArgs(Function.java:747)
at org.h2.expression.Function.getValue(Function.java:352)
at org.h2.expression.Function.optimize(Function.java:1355)
at org.h2.command.dml.Select.prepare(Select.java:460)
at org.h2.command.Parser.prepareCommand(Parser.java:193)
... 8 more


other dates work (as much as I tested) but not 2005-3-31, Please help
with this, I'm really in a deep disaster now :(, this was totally not
foreseen. I really hope that I did something wrong and that this can
be fixed fast.

Eric

unread,
Jun 17, 2007, 11:27:11 AM6/17/07
to H2 Database
I think the format should be '2005-03-31' for dates.


Thomas Mueller

unread,
Jun 17, 2007, 11:27:17 AM6/17/07
to h2-da...@googlegroups.com
Hi,

I have no idea what the problem could be. It works for me (no
exception, correct behavior). Could you please:

- In DateTimeUtils.java, method parseDateTime, add the following line
at the end:

...
} catch(IllegalArgumentException e) {
e.printStackTrace();
...

Then recompile, and try again? A stack trace should be printed to
System.out, and could you then post it here? Also could you tell me
what virtual machine (java -version) you are using, and the locale?
Running 'ant test' will print all the information, the first two
lines.

Thomas

all...@gmail.com

unread,
Jun 17, 2007, 3:38:22 PM6/17/07
to H2 Database
Thomas;

Thanks for the reply, I noticed that when I remove setLenient(false),
it works, let me answer yours first, I use Mac with Java 1.5.0_07

And this is what I get with stack trace

java.lang.IllegalArgumentException: HOUR_OF_DAY
at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:
2481)
at java.util.Calendar.updateTime(Calendar.java:2260)
at java.util.Calendar.complete(Calendar.java:1305)
at java.util.Calendar.get(Calendar.java:1088)
at org.h2.util.DateTimeUtils.parseDateTime(DateTimeUtils.java:203)
at org.iom.finance.FilePath.main(FilePath.java:28)
Exception in thread "main" org.h2.jdbc.JdbcSQLException: Cannot parse


date constant 2005-3-31 [90009-46]
at org.h2.message.Message.getSQLException(Message.java:65)
at org.h2.message.Message.getSQLException(Message.java:47)

at org.h2.util.DateTimeUtils.parseDateTime(DateTimeUtils.java:220)
at org.iom.finance.FilePath.main(FilePath.java:28)

I also tried to force hour to be 1 and it works, something with
calendar I guess :(

On Jun 17, 6:27 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:


> Hi,
>
> I have no idea what the problem could be. It works for me (no
> exception, correct behavior). Could you please:
>
> - In DateTimeUtils.java, method parseDateTime, add the following line
> at the end:
>
> ...
> } catch(IllegalArgumentException e) {
> e.printStackTrace();
> ...
>
> Then recompile, and try again? A stack trace should be printed to
> System.out, and could you then post it here? Also could you tell me
> what virtual machine (java -version) you are using, and the locale?
> Running 'ant test' will print all the information, the first two
> lines.
>
> Thomas
>

Thomas Mueller

unread,
Jun 17, 2007, 3:49:10 PM6/17/07
to h2-da...@googlegroups.com
Hi,

I asked Google about this problem and I found this here:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231602

I am not sure what the best solution is, as it does not look like
there is a workaround. Maybe you need to install another JDK? JDK
1.4.2 should work, or JDK 1.6 (not sure about newer versions of JDK
1.5).

Thomas


On 6/17/07, all...@gmail.com <all...@gmail.com> wrote:
>

all...@gmail.com

unread,
Jun 17, 2007, 4:39:56 PM6/17/07
to H2 Database
yes, I have run the engine with 1.4.2 and it works fine, thanks a lot!
I really didn't need this today :D, I'm glad that I have such a great
help like you are!

On Jun 17, 10:49 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:
> Hi,
>


> I asked Google about this problem and I found this here:
>
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6231602
>
> I am not sure what the best solution is, as it does not look like
> there is a workaround. Maybe you need to install another JDK? JDK
> 1.4.2 should work, or JDK 1.6 (not sure about newer versions of JDK
> 1.5).
>
> Thomas
>

Reply all
Reply to author
Forward
0 new messages