From: teser3 on
I have a JDBC current date and time insert into Oracle 9i that almost
works. It submits the current date and a fixed time into the Oracle
date type field.
For example if I insert the data at 7:24:04 PM on Feb 16, 2010 it will
insert as: 16-Feb-2010 12:00:00 AM
The date part works but the time always shows 12:00:00 AM no matter
what date or time the data is inserted.

Here is what I have for my JDBC inserts:
PreparedStatement ps;
Date mydate = new Date(new java.util.Date().getTime());
//insert statement here....

stmt.setDate(1,mydate);


I also tried:
PreparedStatement ps;
java.sql.Timestamp mydate = new java.util.Date().getTime();
SimpleDateFormat fmt = new SimpleDateFormat(....
//insert statement here....
ps.setTimestamp(1,fmt.format(mydate));

Also tried with DateFormat and still not working.


Both keep submitting the date into Oracle as 16-Feb-2010 12:00:00 AM
Anyway to get the current date and time? For example if I insert the
data at 7:24.04 pm today it should show as 16-Feb-2010 07:24.04 PM in
Oracle.
From: Lew on
teser3(a)hotmail.com wrote:
> I have a JDBC current date and time insert into Oracle 9i that almost
> works. It submits the current date and a fixed time into the Oracle
> date type field.
> For example if I insert the data at 7:24:04 PM on Feb 16, 2010 it will
> insert as: 16-Feb-2010 12:00:00 AM
> The date part works but the time always shows 12:00:00 AM no matter
> what date or time the data is inserted.
>
> Here is what I have for my JDBC inserts:
> PreparedStatement ps;
> Date mydate = new Date(new java.util.Date().getTime());

Which 'Date' type did you use? It looks like you used 'java.sql.Date'.

Check the Javadocs.
Note that that type is not intended to transmit times, just dates.
<http://java.sun.com/javase/6/docs/api/java/sql/Date.html>
>> To conform with the definition of SQL DATE, the millisecond values
>> wrapped by a java.sql.Date instance must be 'normalized' by setting
>> the hours, minutes, seconds, and milliseconds to zero in the
>> particular time zone with which the instance is associated.

teser3(a)hotmail.com wrote:
> //insert statement here....
>
> stmt.setDate(1,mydate);

Check the Javadocs.
<http://java.sun.com/javase/6/docs/api/java/sql/PreparedStatement.html#setDate(int,%20java.sql.Date)>
>> Sets the designated parameter to the given java.sql.Date value ...

teser3(a)hotmail.com wrote:
> I also tried:
> PreparedStatement ps;
> java.sql.Timestamp mydate = new java.util.Date().getTime();

How did you ever get that statement to compile? The 'getTime()' method
returns a 'long', not a 'java.sql.Timestamp'.

> SimpleDateFormat fmt = new SimpleDateFormat(....
> //insert statement here....
> ps.setTimestamp(1,fmt.format(mydate));

What format did you use? You need to provide full information.

Check the Javadocs.

'setTimestamp()' takes a 'Timestamp' argument.
<http://java.sun.com/javase/6/docs/api/java/sql/PreparedStatement.html#setTimestamp(int,%20java.sql.Timestamp)>

'DateFormat#format()' returns a 'String'.

How did you ever get that line to compile?

> Also tried with DateFormat and still not working.
>
> Both keep submitting the date into Oracle as 16-Feb-2010 12:00:00 AM
> Anyway to get the current date and time? For example if I insert the
> data at 7:24.04 pm today it should show as 16-Feb-2010 07:24.04 PM in
> Oracle.

You also need to provide full information with your question. Giving an
example CREATE TABLE and an SSCCE would help a lot. In particular, it would
give an even chance that you'd cite code that actually compiles.

--
Lew