oracle时间戳对应java_Java – Oracle – 数据库插入 – 时间戳到日期列

Oracle中SQL类型和JDBC类型之间的映射有点复杂,特别是对于DATE和TIMESTAMP SQL类型.

Oracle数据库允许您在DATE列中存储时间戳信息,这与SQL标准中DATE的定义完全相反.在9.2之前引入TIMESTAMP列支持时,Statement.setTimestamp将适用于DATE列.从9.2开始,直到11.1,JDBC驱动程序将SQL DATE类型映射到JDBC日期,将SQL TIMESTAMP类型映射到JDBC时间戳.使用10.2 JDBC驱动程序存储时间戳的可能解决方案在Oracle JDBC FAQ中列出,并在此处转载:

There are several ways to address this problem in the 9.2 through 10.2

drivers:

Alter your tables to use TIMESTAMP instead of DATE. This is probably

rarely possible, but it is the best solution when it is.

Alter your application to use defineColumnType to define the columns

as TIMESTAMP rather than DATE. There are problems with this because

you really don’t want to use defineColumnType unless you have to (see

What is defineColumnType and when should I use it? ).

Alter you application to use getTimestamp rather than getObject. This

is a good solution when possible, however many applications contain

generic code that relies on getObject, so it isn’t always possible.

Set the V8Compatible connection property. This tells the JDBC drivers

to use the old mapping rather than the new one. You can set this flag

either as a connection property or a system property. You set the

connection property by adding it to the java.util.Properties object

passed to DriverManager.getConnection or to

OracleDataSource.setConnectionProperties. You set the system property

by including a -D option in your java command line.

java -Doracle.jdbc.V8Compatible=”true” MyApp

您还可以使用JDBC 11.1驱动程序(它们将对10g实例起作用),并且常见问题解答说明:

Oracle JDBC 11.1 fixes this problem. Beginning with this release the driver maps SQL DATE columns to java.sql.Timestamp by default. There is no need to set V8Compatible to get the correct mapping. V8Compatible is strongly deprecated. You should not use it at all. If you do set it to true it won’t hurt anything, but you should stop using it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值