This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
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.