• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 79979
397
  • 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.
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic