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

Home -> Community -> Usenet -> c.d.o.misc -> Re: JDBC to Dates/Times in Oracle

Re: JDBC to Dates/Times in Oracle

From: Jim Kennedy <kennedy-family_at_home.com>
Date: Fri, 16 Nov 2001 01:22:45 GMT
Message-ID: <FTZI7.33145$XJ4.19079121@news1.sttln1.wa.home.com>


All the commercial rdbmss that I know of store date and time as 1 field.(admittedly I don't know them all.) What databases are you thinking of that store it in 2 different fields?

Why not just ignore the component you don't need? So getDate for Oracle would just get the date part and getTime would just get the time part.

You are going to have to write database specific code in any event or you are going to have to code for the lowest common denominator which will give you a whole set of other problems.

Jim

"Neil Campbell" <campben8_at_cs.man.ac.uk> wrote in message news:3BF3BAC0.B6A2DAD0_at_cs.man.ac.uk...
> In creating a Java/JDBC application that needs to be database
> independant, I need to store dates and times. In several databases,
> this is straightforward as java.sql.Date and java.sql.Time map onto the
> corresponding SQL types in the database. However, from what I can find
> in the Oracle documentation, Oracle has instead a Date type which
> includes both date and time info.
>
> How do I create two separate fields in Oracle which store (or at least,
> appear to) ONLY one component, ie date in one, time in the other? The
> java code would be something like:
>
> //do query
> ...
> //get results
> Date d1 = results.getDate(1);
> Time t1 = results.getTime(2);
>
> Clearly if I write to a single field containing both date and time (as
> in Oracle) this would render the code incompatible to other dbs which
> separate the two.
>
> A quick Google search for similar questions suggests storing strings or
> numeric data in the db instead, which can of course be handled by all
> the databases, but this solution seems somewhat unsatisfactory, in that
> the semantics of the date type are lost in the conversion.
>
> I'd really appreciate any suggestions and/or pointers to other useful
> information.
>
> Thanks,
> Neil
Received on Thu Nov 15 2001 - 19:22:45 CST

Original text of this message

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