Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getDate() not working correctly in Oracle 12.x driver

castorpNov 9 2015 — edited Feb 12 2016

According to the JDBC FAQ and this discussion:

setting the connection property "oracle.jdbc.mapDateToTimestamp" to "false" should make sure that the time part of a DATE column is correctly set to 00:00:00 as required by the JDBC API.

This has been working fine with the 11.x drivers, however when upgrading the driver to 12.1.0.1 or 12.1.0.2 this property does not work any longer. Assume the following test data:

create table date_test (some_date date)

insert into date_test values (to_date('2015-11-09 19:20:21', 'yyyy-mm-dd hh24:mi:ss'));

and the following simple Java code:

Properties props = new Properties();

props.put("user", "*****");

props.put("password", "****");

props.put("mapDateToTimestamp", "false");

Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/oradb", props);

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

ResultSet rs = stmt.executeQuery("select * from date_test");

     

while (rs.next()) {

   System.out.println("getDate: " + sdf.format(rs.getDate(1)));

   System.out.println("getTimestamp: " + sdf.format(rs.getTimestamp(1)));

}

rs.close();

I tried "mapDateToTimestamp" as the property name as well as "oracle.jdbc.mapDateToTimestamp"

Using the 11.2.0.4 driver against a 12.1.0.2 database the above code prints (correctly):

getDate: 2015-11-09 00:00:00

getTimestamp: 2015-11-09 19:20:21

Using the 12.1.0.2 driver the above code prints

getDate: 2015-11-09 19:20:21

getTimestamp: 2015-11-09 19:20:21

So getDate() with the 12.x driver clearly does not return an instance of java.sql.Date that is "'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated"  (quoted from: Date (Java Platform SE 7 ))

So how do we get back the correct JDBC behaviour with the 12.x drivers?

I also tried setting "oracle.jdbc.JDBCStandardBehavior" to "true" but that didn't change the behaviour either.


Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 11 2016
Added on Nov 9 2015
5 comments
6,662 views