• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic