Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Oracle 10g returns DATE as java.sql.Date?

Re: Oracle 10g returns DATE as java.sql.Date?

From: Joe Weinstein <joeNOSPAM_at_bea.com>
Date: Wed, 09 Nov 2005 12:00:28 -0800
Message-ID: <4372555C.3090700@bea.com>

thomas_okken_at_hotmail.com wrote:

> I noticed that Oracle 10g XE, with the ojdbc14.jar JDBC driver, returns
> DATE columns as java.sql.Date valuess. That surprised me, because the
> ResultSetMetaData claims the column's Java type is java.sql.Timestamp
> -- which would make more sense since DATE columns contain date *and*
> time information, just just date.
> I seem to remember that Oracle 8i did return java.sql.Timestamp for
> DATE columns.
> Did they change this, or am I just misremembering? Is there a way to
> get the driver to return java.sql.Timestamp?

Hi. Oracle made a mistake (in my opinion) in this regard. They made a new DBMS column type 'TIMESTAMP' which is semantically the same as DATE, except it has more precision. The driver now maps that column to a java.sql.TIMESTAMP, but Oracle incorrectly demoted it's map of the DATE column to a java.sql.Date, which loses data by default if you do a getObject. This is as if they made a new 'SUPERNUMBER' column that could hold 50 decimal digits, and then demoted their NUMBER column map to an integer.

   Enough rant. You can get the previous mapping by adding this property to your connection:

       prop.put ("oracle.jdbc.V8Compatible", "true");

and you should be safely "back in Kansas". Let me know...

Joe Weinstein at BEA Systems Received on Wed Nov 09 2005 - 14:00:28 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US