aspose file tools*
The moose likes JDBC and the fly likes How to create date object with this format  2008-08-08 10:12:35:333 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to create date object with this format  2008-08-08 10:12:35:333" Watch "How to create date object with this format  2008-08-08 10:12:35:333" New topic
Author

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

sivakumar panchu
Greenhorn

Joined: Jul 18, 2007
Posts: 20
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.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Evgeniy Bulanov
Greenhorn

Joined: Dec 19, 2005
Posts: 23
sivakumar panchu,

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

--
JK


Computers are like air conditioners - They stop working properly when you open Windows
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

alternatively you can use

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


Thanks,
Shailesh
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39865
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create date object with this format 2008-08-08 10:12:35:333