Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Java Datestamp format question

807605Oct 5 2007 — edited Oct 5 2007
Hi all,

I have a column in a SQL Server database of type DATESTAMP and I want to put the exact time of a certain action in there when a record is added. But the timestamp seems to be causing me trouble when I try to insert it.

So far I have this (params array just holds the insert values, the SQL strings are constructed using MessageFormat objects) :
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyy HH:mm:ss:SSS");
Date date = new Date(new java.util.Date().getTime());
params[11] = sdf.format(date);
But it doesn't work due to it beign an "invalid timestamp value". I've also tried:
Date date = new Date(new java.util.Date().getTime());
Timestamp tStamp = new Timestamp(date.getTime());
params[11] = tStamp;
But no joy. Note that "date" is of the Java.sql variety. Can anyone tell me the Java equivalent of the SQL TIMESTAMP datatype?

Cheers,

Illu
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2007
Added on Oct 5 2007
4 comments
287 views