I ran into a similar problem the other day where the time component was being truncated from some dates.
We narrowed it down to a difference in Oracle Driver versions.
On Oracle's FAQ there is a section about this:
select sysdate from dual; ...while(rs.next())
Prior to 9201, this will return:
getObject for sysdate : java.sql.Timestamp <<<<
getDate for sysdate : java.sql.Date
getTimetamp for sysdate : java.sql.Timestamp
As of 9201 onward the following will be returned
getObject for sysdate : java.sql.Date <<<<<
getDate for sysdate :java.sql.Date >> no change
getTimetamp for sysdate :java.sql.Timestamp >> no change
Note: java.sql.Date has no time portion whereas java.sql.Timestamp does.
With this change in Datatype mapping, some application will fail and/or generate incorrect results when JDBC driver is upgraded from 8i/ 9iR1 to 920x JBDC driver.
To maintain compatibility and keep applications working after upgrade, a compatibility flag was Provided. Developers now have some options:
- Use oracle.jdbc.V8Compatible flag.
JDBC Driver does not detect database version by default. To change the compatibility flag for handling TIMESTAMP datatypes, connection property
'oracle.jdbc.V8Compatible'
can be set to 'true' and the driver behaves as it behaved in 8i, 901x, 9 200 (with respect to TIMESTAMPs).
By default the flag is set to 'false'. In OracleConnection constructor the driver obtains the server version and set the compatibility flag appropriately.
java.util.Properties prop=newjava.util.Properties();
prop.put("oracle.jdbc.V8Compatible","true");
prop.put("user","scott");
prop.put("password","tiger");
String url="jdbc:oracle:thin:@host:port:sid";
Connection conn = DriverManager.getConnection(url,prop);
With JDBC 10.1.0.x, instead of the connection property, the following system property can be used: java -Doracle.jdbc.V8Compatible=true.....Note: This flag is a client only flag that governs the Timestamp and Date mapping. It does not affect any Database feature.
'2. Use set/getDate and set/getTimestamp when dealing with Date and TimeStamp column data type accordingly.
9i server supports both Date and Timestamp column types DATE is mapped to java.sql.Date and TIMESTAMP is mapped to java.sql.Timestamp.
So for my situation, I had code like this:
import java.util.Date;
Date d = rs.getDate(1);
With 9i I was getting a java.sql.Timestamp (which is a subclass of java.util.Date) so everything was groovy and I had my hours and minutes.
But with 10g, the same code now gets a java.sql.Date (also a subclass of java.util.Date so it still compiles) but the HH:MM is TRUNCATED!!.
The 2nd solution was pretty easy for me - just replace the getDate with getTimestamp and you should be OK. I guess that was a bad habit.