Java ojdbc14.jar 与 ojdbc6.jar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3209647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:25:58  来源:igfitidea点击:

ojdbc14.jar vs. ojdbc6.jar

javaoraclejdbc

提问by Omnipresent

I noticed the following difference but did not see it documented anywhere. I'm wondering if others have noticed the same thing or can point me to some documentations that proves the same.

我注意到以下差异,但没有在任何地方看到它的记录。我想知道其他人是否注意到了同样的事情,或者可以指出一些证明相同的文件。

Env:-

环境:-

Oracle 11g, JDK 1.6, iBatis, PL/SQL

Oracle 11g, JDK 1.6, iBatis, PL/SQL

Scenario:-

设想:-

ojdbc14.jar: if pl/sql returns a variable of type DATEand I try to put that in a java.sql.Date variable then everything works fine. Example:

ojdbc14.jar:如果 pl/sql 返回一个类型的变量DATE并且我尝试将它放在 java.sql.Date 变量中,那么一切正常。例子:

Date annualDate = (Date) map.get("exam_date");

Date annualDate = (Date) map.get("exam_date");

ojdbc6.jar: if pl/sql returns a variable of type DATEand I try to put that in a java.sql.Date variable then I get an exception:

ojdbc6.jar:如果 pl/sql 返回一个类型的变量DATE并且我尝试将它放在 java.sql.Date 变量中,那么我得到一个异常:

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.sql.Date

采纳答案by Pascal Thivent

Actually, ojdbc14.jardoesn't really say anything about the real version of the driver (see JDBC Driver Downloads), except that it predates Oracle 11g. In such situation, you should provide the exact version.

实际上,ojdbc14.jar并没有真正说明驱动程序的真实版本(请参阅JDBC 驱动程序下载),只是它早于 Oracle 11g。在这种情况下,您应该提供确切的版本。

Anyway, I think you'll find some explanation in What is going on with DATE and TIMESTAMP?In short, they changed the behavior in 9.2 drivers and then again in 11.1 drivers.

无论如何,我想你会在 DATE 和 TIMESTAMP 发生什么事情中找到一些解释简而言之,他们更改了 9.2 驱动程序中的行为,然后又更改了 11.1 驱动程序中的行为。

This might explain the differences you're experiencing (and I suggest using the most recent version i.e. the 11.2 drivers).

这可能可以解释您遇到的差异(我建议使用最新版本,即 11.2 驱动程序)。

回答by duffymo

The "14" and "6" in those driver names refer to the JVM they were written for. If you're still using JDK 1.4 I'd say you have a serious problem and need to upgrade. JDK 1.4 is long past its useful support life. It didn't even have generics! JDK 6 u21 is the current production standard from Oracle/Sun. I'd recommend switching to it if you haven't already.

这些驱动程序名称中的“14”和“6”指的是它们所针对的 JVM。如果您仍在使用 JDK 1.4,我会说您有一个严重的问题,需要升级。JDK 1.4 早已过了其有用的支持寿命。它甚至没有泛型!JDK 6 u21 是 Oracle/Sun 的当前生产标准。如果您还没有,我建议您切换到它。

回答by Aram Arabyan

I have same problem!

我有同样的问题!

Found following in oracle site link text

在 oracle 站点链接文本中找到以下 内容

As mentioned above, the 11.1 drivers by default convert SQL DATE to Timestamp when reading from the database. This always was the right thing to do and the change in 9i was a mistake. The 11.1 drivers have reverted to the correct behavior. Even if you didn't set V8Compatible in your application you shouldn't see any difference in behavior in most cases. You may notice a difference if you use getObject to read a DATE column. The result will be a Timestamp rather than a Date. Since Timestamp is a subclass of Date this generally isn't a problem. Where you might notice a difference is if you relied on the conversion from DATE to Date to truncate the time component or if you do toString on the value. Otherwise the change should be transparent.

如上所述,11.1 驱动程序在从数据库读取时默认将 SQL DATE 转换为 Timestamp。这始终是正确的做法,而 9i 中的更改是一个错误。11.1 驱动程序已恢复到正确的行为。即使您没有在应用程序中设置 V8Compatible,在大多数情况下您也不应该看到任何行为差异。如果您使用 getObject 读取 DATE 列,您可能会注意到不同。结果将是时间戳而不是日期。由于 Timestamp 是 Date 的子类,因此这通常不是问题。您可能会注意到不同之处在于,您是否依赖从 DATE 到 Date 的转换来截断时间组件,或者您是否对值执行 toString 操作。否则,更改应该是透明的。

If for some reason your app is very sensitive to this change and you simply must have the 9i-10g behavior, there is a connection property you can set. Set mapDateToTimestamp to false and the driver will revert to the default 9i-10g behavior and map DATE to Date.

如果出于某种原因,您的应用程序对这种更改非常敏感,并且您必须具有 9i-10g 行为,那么您可以设置一个连接属性。将 mapDateToTimestamp 设置为 false,驱动程序将恢复到默认的 9i-10g 行为并将 DATE 映射到 Date。

回答by Paulo Merson

Also, from ojdbc14 to ojdbc6, several types (e.g., OracleResultSet, OracleStatement) moved from package oracle.jdbc.driverto oracle.jdbc.

此外,从 ojdbc14 到 ojdbc6,几种类型(例如OracleResultSet, OracleStatement)从包移动oracle.jdbc.driveroracle.jdbc.