Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sivakumar panchu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
Evgeniy Bulanov
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sivakumar panchu,

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

--
JK
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alternatively you can use

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


Thanks,
Shailesh
 
Campbell Ritchie
Sheriff
Posts: 51439
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic