aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes oracle date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "oracle date format" Watch "oracle date format" New topic
Author

oracle date format

Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
I have a table in oracle(8i) which contains a column with type DATE. If I want to insert something in this column through CMP, and I use java.sql.Timestamp for this column, it works perfectly. But if I retrieve the value of this field through CMP, it gives the Timestamp object whose format is quite different from the regular Timestamp object.
The timestamp object returned from the CMP is :
4-04-10 10:00:00.0
And the timestamp object created from system time, - new java.sql.Timestamp( System.currentTimeMillis() ) is
2004-04-12 17:26:24.03
Plus, if I try to get the milliseconds from the Timestamp object returned from the CMP, it prints a large negative value.
In my application, I want to compare the timestamp object created from the current system time with the one returned from the CMP bean.
What should be the solution to this?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30919
    
158

Ankit,
The easiest way to compare to timestamp objects is time1.compareTo(time2).
The format of your two objects looks the same to me. For some reason, it thinks the year you entered is the year 4 rather than 2004. Is this date coming from a web page by any chance?
This also explains the large negative value. The year 4 is quite a bit before the year 1970.


[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
Ankit Doshi
Ranch Hand

Joined: Dec 04, 2002
Posts: 222
I am inserting the records in the database manually by firing "insert into" statements at the SQL prompt and passing SYSDATE as the value of the date field. And yeah, the CMP is actually giving me the year as 0004 instead of 2004. Could that be a problem with the application server? I am using jboss 2.4. Here, while inserting, if I use only date (without time) - trunc(SYSDATE), and if I change the CMP field type to java.sql.Date, rather than java.sql.Timestamp, then it gets correct format from the CMP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: oracle date format