H2数据库-Java的OffsetDateTime和H2类型之间的映射

H2数据库-Java的OffsetDateTime和H2类型之间的映射,java,jdbc,timestamp,h2,sql-timestamp,Java,Jdbc,Timestamp,H2,Sql Timestamp,我使用的是单元测试 根据官方H2文档,Java的OffsetDateTime和H2数据类型TIMESTAMP WITH TIME ZONE映射到Java的H2 TIMESTAMP WITH Timezone类型之间没有映射,这不是我需要的 有什么方法可以实现这一点吗?虽然普通的GetObjective columnIndex确实会返回org.h2.api.timestamWithTimeZone对象,但使用GetObjective columnIndex,类类型返回java.time.Offse

我使用的是单元测试

根据官方H2文档,Java的OffsetDateTime和H2数据类型TIMESTAMP WITH TIME ZONE映射到Java的H2 TIMESTAMP WITH Timezone类型之间没有映射,这不是我需要的


有什么方法可以实现这一点吗?

虽然普通的GetObjective columnIndex确实会返回org.h2.api.timestamWithTimeZone对象,但使用GetObjective columnIndex,类类型返回java.time.OffsetDateTime对于我来说似乎可以使用h2版本1.4.196:

包装试验; 导入java.sql.*; 导入java.time.OffsetDateTime; 公共类H2testMain{ 公共静态无效字符串[]args{ 尝试连接conn=DriverManager.getConnectionjdbc:h2:mem:test{ 语句st=conn.createStatement; st.executeCREATE表测试ID INT主键,带时区的TWTZ时间戳; st.executeINSERT进入测试ID,TWTZ值1,'1981-02-03 19:20:21-02:00'; ResultSet rs=st.executequery从测试中选择TWTZ,其中ID=1; rs.next; OffsetDateTime odt=rs.getObject1,OffsetDateTime.class; System.out.printlnodt.getClass.getName;//java.time.OffsetDateTime System.out.printlnodt.toString;//1981-02-03T19:20:21-02:00 }捕获异常e{ e、 printStackTraceSystem.err; } } }