jQuery in Action, 2nd edition*
The moose likes Object Relational Mapping and the fly likes Oracle Date and Time problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Oracle Date and Time problem" Watch "Oracle Date and Time problem" New topic
Author

Oracle Date and Time problem

Nagaseshagiri poola
Greenhorn

Joined: Oct 18, 2003
Posts: 25
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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Nagaseshagiri poola
Greenhorn

Joined: Oct 18, 2003
Posts: 25
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

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


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Nagaseshagiri poola
Greenhorn

Joined: Oct 18, 2003
Posts: 25
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oracle Date and Time problem
 
Similar Threads
Date formatting in java.
Passing date and time using Timestamp.
DB2 Date format to Oracle Date format?
Insert the current date
how to map Date