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 -> JDBC to Dates/Times in Oracle

JDBC to Dates/Times in Oracle

From: Neil Campbell <campben8_at_cs.man.ac.uk>
Date: Thu, 15 Nov 2001 12:53:20 +0000
Message-ID: <3BF3BAC0.B6A2DAD0@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 - 06:53:20 CST

Original text of this message

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