Hi Noel,
Thanks for your quick response firstly. I try to insert a record using
preparedstatement but fails.
My codes is:
>
>
>
>
>
>
>
> * JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); String
> insertSql = "insert into TEST_TIME values (?, ?)"; // current time with
> time zone UTC+8 final TimestampWithTimeZone ts = new
> TimestampWithTimeZone(new Date().getTime(), 0, (short) 8);
> jdbcTemplate.update(insertSql, new PreparedStatementSetter() { @Override
> public void setValues(PreparedStatement ps) throws SQLException {
> ps.setInt(1, 1); ps.setObject(2, ts); *//*ps.setTimestamp(2, ts)*
> //have same result as setObject()
> * } });*
The execution of the above code fails with an exception:
> *INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL,
> MySQL, Oracle, PostgreSQL, Sybase, Hana] *
> *[error] (run-main-6) org.springframework.jdbc.UncategorizedSQLException:
> PreparedStatementCallback; uncategorized SQLException for SQ*
> *0000]; General error: "java.lang.ArrayIndexOutOfBoundsException: 2048";
> SQL statement: *
> *[error] insert into TEST_TIME values (?, ?) [50000-192]; nested exception
> is org.h2.jdbc.JdbcSQLException: General error: "java.lang.*
> *[error] insert into TEST_TIME values (?, ?) [50000-192]
> *
> *org.springframework.jdbc.UncategorizedSQLException:
> PreparedStatementCallback; uncategorized SQLException for SQL [insert into
> TEST_T*
> * "java.lang.ArrayIndexOutOfBoundsException: 2048"; SQL statement:
> *
> *insert into TEST_TIME values (?, ?) [50000-192]; nested exception is
> org.h2.jdbc.JdbcSQLException: General error: "java.lang.ArrayInd*
> *insert into TEST_TIME values (?, ?) [50000-192]
> *
> * at
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.j*
> * at
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.j*
> * at
> org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.j*
> * at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649)
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:870)
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:931)
> *
> * at org.kriss.MyJava.main(MyJava.java:31)
> *
> * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> *
> * at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> *
> * at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> *
> * at java.lang.reflect.Method.invoke(Method.java:606)
> *
> *Caused by: org.h2.jdbc.JdbcSQLException: General error:
> "java.lang.ArrayIndexOutOfBoundsException: 2048"; SQL statement:
> *
> *insert into TEST_TIME values (?, ?) [50000-192]
> *
> * at
> org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
> *
> * at org.h2.message.DbException.get(DbException.java:168)
> *
> * at org.h2.message.DbException.convert(DbException.java:295)
> *
> * at org.h2.table.RegularTable.addRow(RegularTable.java:137)
> *
> * at org.h2.command.dml.Insert.insertRows(Insert.java:156)
> *
> * at org.h2.command.dml.Insert.update(Insert.java:114)
> *
> * at
> org.h2.command.CommandContainer.update(CommandContainer.java:98)
> *
> * at org.h2.command.Command.executeUpdate(Command.java:258)
> *
> * at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:160)
>
> *
> * at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:146)
>
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:877)
>
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:870)
>
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:870)
> *
> * at
> org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:931)
> *
> * at org.kriss.MyJava.main(MyJava.java:31)
> *
> * at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> *
> * at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> *
> * at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>
> *
> * at java.lang.reflect.Method.invoke(Method.java:606)
> *
> *Caused by: java.lang.ArrayIndexOutOfBoundsException: 2048
> *
> * at org.h2.store.Data.writeByte(Data.java:386)
> *
> * at org.h2.store.Data.writeValue(Data.java:558)
> *
> * at org.h2.index.PageDataLeaf.addRowTry(PageDataLeaf.java:217)
> *
> * at org.h2.index.PageDataIndex.addTry(PageDataIndex.java:172)
> *
> * at org.h2.index.PageDataIndex.add(PageDataIndex.java:135)
> *
> * at org.h2.table.RegularTable.addRow(RegularTable.java:119)
> *
> * at org.h2.command.dml.Insert.insertRows(Insert.java:156)
> *
> * at org.h2.command.dml.Insert.update(Insert.java:114)
> *
> * at
> org.h2.command.CommandContainer.update(CommandContainer.java:98)
> *
> * at org.h2.command.Command.executeUpdate(Command.java:258)
> *
> * at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:160)
>
> ** at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:146)
>
> *
But it does insert a record in the table TEST_TIME although the time
zone(UTC+8) info is missing :
SELECT * FROM TEST_TIME;
> ID
> <http://192.168.56.1:8082/query.do?jsessionid=41f5e73e91481c34190c76ecd4fe122e#>
> NAME
> <http://192.168.56.1:8082/query.do?jsessionid=41f5e73e91481c34190c76ecd4fe122e#>
> 1 2016-09-06 14:41:05.0+00(1 row, 8 ms)
Could you please have a look at where the issue is? It is greatly
appreciated that you can provide a workable sample about inserting
"timestamp with timezone" record. Thanks!
在 2016年9月6日星期二 UTC+8上午10:10:26,Kriss Lu写道:
>
>
> Hi Noel,
> Thanks for your quick response. I will have a try.
>
>
> 在 2016年9月5日星期一 UTC+8下午7:05:16,Noel Grandin写道:
>>
>> Currently, all it supports is
>>
>> (a) ISO 8601 time in string format.
>> https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators
>>
>> (b) using preparedstatement and org.h2.api.TimestampWithTimeZone
>>
>>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.