This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

Oracle Date and Time problem  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
am using hibernate to store the data in to database. Oracle version is 10g. when i insert the date value in to Oracle Date field. its taking "dd/mm/yyyy" format. i want that to be "dd/mm/yyyy hh:mm:ss a" like "06/22/2006 11:24:34 PM". In the hibernate pojo field data type is java.sql.date.

i tried "new Timestamp(System.currentTimeMillis())", new Timestamp(new Date().getTime()) etc. please let me know the solution.

Note : i cant change the field type in table.
 
author & internet detective
Posts: 39084
714
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagaseshagiri,
From Java's end of things, you can solve this problem by using a PreparedStatement. Then you just call prepStmt.setTimeStamp(timestamp) and don't have to worry about the format.
 
Nagaseshagiri poola
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion. Am using Hibernate with Spring which handles the Database operations. Please let me know if there is any other alternative from java end to set the timestamp as needed.

Thanks in advance
 
Jeanne Boyarsky
author & internet detective
Posts: 39084
714
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used Hibernate, so I can't personally comment on this.

I'm moving your post to the Object Relational forum where the Hibernate experts hang out.
 
Ranch Hand
Posts: 1085
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagaseshagiri,

I guess you have only played with value date only but have you mapped your db column to java.sql.Timestamp type in your code.

I would recommend that whatever is your data column in database, map it to java.sql.TimeStamp and provide your value as timestamp

Shailesh
 
Nagaseshagiri poola
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thansk for the message.
I even tried with the Hibernate mapping n when i changed the property value from "date" to sql timestamp, hibernate is throwing error : cannot find the matches for the type timestamp.
I changed the Oracle data type to TIMESTAMP and i had new problem as time is stored as "mm/dd/yyyy 12:00:00:00,000 AM". Time is stored as default 12:00:00 AM and its not right. it is not taking the right time.

Please help me out.
 
He was giving me directions and I was powerless to resist. I cannot resist this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!