Restore DB from SQL: Cannot parse date constant ?676-10-10

340 views
Skip to first unread message

satio

unread,
Mar 30, 2010, 5:28:58 AM3/30/10
to H2 Database
Hi, I have a question..
e.g :
I input a date --> DATE '19676-12-23' (year-month-date with the year
is 5 digit = invalid),
It is invalid date but when I do insert, it can be saved into the
Database successfully (No Error)..
When I do backup the Database ('backup-sql.bak'), there is no error
too, the backup.bak is created..
But when i want to restore using that 'backup-sql.bak', it generates
below error:

org.h2.jdbc.JdbcSQLException: Cannot parse date constant ?676-10-10,
cause: java.lang.NumberFormatException: For input string: "?676"; SQL
statement:
Caused by: java.lang.NumberFormatException: For input string: "?676"
Note: ? is box (somehow unable to copy paste the symbol in here)

What cause this error??
Why when I insert the invalid date and backup, there is no error, but
when i restore there is an error?
Why not when I insert the invalid date and backup, it shows the error
too..?

How should I do to restore this broken sql backup?

Thomas Mueller

unread,
Mar 31, 2010, 2:28:21 PM3/31/10
to h2-da...@googlegroups.com
Hi,

The problem is that java.sql.Date.toString() doesn't support years
beyond 9999. You will get the same or a similar result using:

System.out.println(java.sql.Date.valueOf("19676-01-01").toString());

However I will implement a workaround in H2, so that the following
test will work:

Connection conn;
conn = DriverManager.getConnection(
"jdbc:h2:data/test", "sa", "sa");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("call date '19676-12-23'");
rs.next();
Timestamp ts = rs.getTimestamp(1);
System.out.println(ts);
java.sql.Date d = rs.getDate(1);
System.out.println(d); // can't be fixed
System.out.println(rs.getString(1));

The next version of H2 will print:

19676-12-23 00:00:00.0

Christian Peter

unread,
Mar 31, 2010, 3:55:57 PM3/31/10
to H2 Database
Hi Thomas,

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

Since Java 6u18 java.sql.Date.valueOf() throws exceptions if not in
yyyy-mm-dd format. I just checked in a fix for RandomGen.randomDate().
You should check if everywhere else the handling is correct.

Regards

Christian

On Mar 31, 8:28 pm, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

satio

unread,
Apr 1, 2010, 12:54:44 AM4/1/10
to H2 Database
Oh, I see.. Thanks.

On Apr 1, 2:55 am, Christian Peter <christian.peter...@googlemail.com>
wrote:
> Hi Thomas,
>
> seehttp://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6898593

Reply all
Reply to author
Forward
0 new messages