开发者

ojdbc14.jar vs. ojdbc6.jar

开发者 https://www.devze.com 2023-01-06 08:40 出处:网络
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.

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.

E开发者_StackOverflownv:-

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

Scenario:-

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

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

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

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


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.


Actually, ojdbc14.jar doesn'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.

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.

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


I have same problem!

Found following in oracle site link text

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.

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消