JDBC 12c Adds Timestamp to java.sql.Date After Upgrading From 11.2.0.4

(Doc ID 1944845.1)

Last updated on JULY 06, 2017

Applies to:

JDBC - Version 12.1.0.1.0 and later
Information in this document applies to any platform.

Symptoms

The behavior of setDate() has changed starting with Oracle JDBC Driver 12.1.0.1.
As result, time is inserted into DATE column if using setDate() method.

From Oracle JDBC Driver 12.1.0.1 : the time is inserted as defined in the variables.
Oracle JDBC Driver 11.2.0.4 or earlier : the driver sets the time to "00:00:00".

Sample Code :

PreparedStatement ps = conn.prepareStatement("insert into emp(empno, hiredate) values(1111, ?)");
Date cd = new Date(System.currentTimeMillis());
ps.setDate(1, cd);
ps.execute();

Results :

Execute "select to_char(hiredate, 'DD-MON-YYYY HH24:MI:SS') from emp" statements,
the result is like follows.

- JDBC Driver 11.2.0.4 and earlier version : 12-NOV-2014 00:00:00
- JDBC Driver 12.1.0.1 and later : 12-NOV-2014 16:14:48

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms