Forums Register Login

How to create date object with this format 2008-08-08 10:12:35:333

+Pie Number of slices to send: Send
HI,

I am working in web project .I want to insert current DateTime in the db,The current_DateTime column is primarykey.If i insert more than one record its giving DuplicateKeyException: ORA-00001: violation de contrainte unique .
So i want to know how to create date object with dateformat like this (yyyy-mm-dd hh:mm:s:sss).


Thanks.
+Pie Number of slices to send: Send
A date object does not have a format, you can convert it to any format using DateFormat class.

I think you are inserting Date using the java.sql.Date in your program. actually java.sql.Date removes the time part from the date.

Thanks,
Shailesh
+Pie Number of slices to send: Send
 


yyyy-mm-dd hh:mm:s:sss


In Oracle a DATE datatype does not include fractional seconds. You'll need to use a TIMESTAMP.
[ August 21, 2008: Message edited by: Paul Sturrock ]
+Pie Number of slices to send: Send
sivakumar panchu,

to format date use SimpleDateFormater in java and to_date() function in oracle.

--
JK
+Pie Number of slices to send: Send
alternatively you can use

preparedStatement.setTimeStamp(index, new Timestamp(System.currentTimeMillis())); //or your pass your date in long


Thanks,
Shailesh
+Pie Number of slices to send: Send
And why did you use the time as a primary key in the first place? That implies an impossible constraint, that you cannot have two entries arriving simultaneously.
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1197 times.
Similar Threads
Oracle DATE field issue ...
simple date
Java Date formatting problem
Date Query
Question on Creation of a Date Object
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:07:33.