Re: Date different
- From: steve <steve@xxxxxxx>
- Date: Fri, 14 Oct 2005 06:14:05 +0800
On Thu, 13 Oct 2005 12:31:51 +0800, Roedy Green wrote
(in article <ppork1d62ld9se84t1vu0rt8ud5tievh9j@xxxxxxx>):
> On Wed, 12 Oct 2005 17:05:24 +0800, steve <steve@xxxxxxx> wrote or
> quoted :
>
>> i tracked it down!!
>> oracle changed the default types returned for their newest oracle drivers,
>> so
>> getobject() actually returns the WRONG type.
>
> I thought JDBC was supposed to bypass that nonsense.
>
well jdbc only return what the database tells it.
This is what oracle have to say on the matter.
What is going on with DATE and TIMESTAMP?
This section is on simple data types. :-)
Prior to 9.2, the Oracle JDBC drivers mapped the DATE SQL type to
java.sql.Timestamp. This made a certain amount of sense because the Oracle
DATE SQL type contains both date and time information as does
java.sql.Timestamp. The more obvious mapping to java.sql.Date was somewhat
problematic as java.sql.Date does not include time information. It was also
the case that the RDBMS did not support the TIMESTAMP SQL type, so there was
no problem with mapping DATE to Timestamp.
In 9.2 TIMESTAMP support was added to the RDBMS. The difference between DATE
and TIMESTAMP is that TIMESTAMP includes nanoseconds and DATE does not. So,
beginning in 9.2, DATE is mapped to Date and TIMESTAMP is mapped to
Timestamp. Unfortunately if you were relying on DATE values to contain time
information, there is a problem.
There are several ways to address this problem:
? 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 i
s a good solution when possible, however many applications contain generic
code that relies on getObject, so it isn't always possible.
? Set the V8Compatibility connection property. This tells the JDBC driver
s 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.V8Compatibility="true" MyApp
which basically means that if you coded for date returning timestanp it
worked.
the "alter your application" solution is just stupid, as you now have to
produce either table specific java code or check the metadata and filter
out the dates.
changing you table to timestamp , means exporting the data , and scrapping
off the old table , rebuilding it , and then re-importing the data.
their solution of mapping date to date , is still wrong, because date still
returns time information , which is lost in the translation to date.
to make it more complex, on the return trip back to the database, if you use
stored sql procedures to write the data back to the database, they are also
now broken.
because they are expecting a "Date", but now oracle has returned a
"Timestamp"
.
- Follow-Ups:
- Re: Date different
- From: P.Hill
- Re: Date different
- References:
- Date different
- From: News-proxy.phk.philips.com
- Re: Date different
- From: P.Hill
- Re: Date different
- From: steve
- Re: Date different
- From: P.Hill
- Re: Date different
- From: steve
- Re: Date different
- From: Roedy Green
- Date different
- Prev by Date: Re: Quick Cash in Weeks!
- Next by Date: Re: recursive function
- Previous by thread: Re: Date different
- Next by thread: Re: Date different
- Index(es):
Relevant Pages
|