本文介绍了在oracle.sql.TIMESTAMPTZ和DbUnit的标准JDBC类之间进行转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Oracle 10g,并且具有带有Type_Name的列

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

TIMESTAMP(6) WITH TIME ZONE

当膨胀为Java类时,它们显示为

When inflated into java classes they come out as

oracle.sql.TIMESTAMPTZ 

但是DbUnit无法处理将Oracle特定的类转换为用于写入XML的字符串.我想知道是否有任何简单的方法可以将这些Oracle特定的时间戳(例如,以某种方式在SELECT语句中)转换为java.sql中的某些内容.

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.

推荐答案

我不必完全解决此问题,但我认为将它作为SELECT查询中的字符串来处理就可以了.

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.

您可以使用 to_char 功能.将其转换为字符串.例如:

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

然后您的程序会将其视为字符串. TZD包含时区信息(在此示例中没有时区信息)

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

稍后,Java可以使用 SimpleDateFormat 类.

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

或者, oracle.sql. TIMESTAMPTZ 类具有一个称为dateValue的方法,该方法返回一个java.sql.Date类.

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

这篇关于在oracle.sql.TIMESTAMPTZ和DbUnit的标准JDBC类之间进行转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 03:19