Converting between oracle.sql.TIMESTAMPTZ and standard JDBC classes for DbUnit

邮差的信 提交于 2019-12-24 07:58:30

问题


I'm running Oracle 10g and have columns with Type_Name

TIMESTAMP(6) WITH TIME ZONE

When inflated into java classes they come out as

oracle.sql.TIMESTAMPTZ 

But DbUnit can't handle converting Oracle specific classes to Strings for writing to XML. I'm wondering if there's any easy way for me to convert (say, in my SELECT statement somehow) from these Oracle specific timestamps to something in java.sql.


回答1:


I haven't had to deal with this problem exactly, but I presume that having it come through as a string from the SELECT query would be fine.

You could use the to_char function. To convert it to a string. e.g:

SQL> select to_char(systimestamp, 'YYYY-MM-DD HH24:MI:SS.FF TZD') as d from dual;

D
----------------------------------
2008-10-21 17:00:43.501591

This would then be seen by your program as a string. TZD includes timezone information (of which there is none in this example)

Later, this could then be parsed by Java using the SimpleDateFormat class.

Alternatively, the oracle.sql.TIMESTAMPTZ class has a method called dateValue that returns a java.sql.Date class.




回答2:


I would like to remark that using IYYY as format for the year might not be a good idea unless you really want to get the ISO year. You should use YYYY instead of IYYY.

Try to run your SQL for 31.12.2012 using

select to_char(timestamp'2012-12-31 00:00:00 +00:00', 'IYYY-MM-DD HH24:MI:SS.FF TZD') as d from dual;

returns "2013-12-31 00:00:00.000000000" which is not the year you would expect.



来源:https://stackoverflow.com/questions/223096/converting-between-oracle-sql-timestamptz-and-standard-jdbc-classes-for-dbunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!