JDBC Application Does Not Reflect The DST Changes That Take Effect In The Database (Doc ID 979242.1)

Last updated on JULY 09, 2012

Applies to:

JDBC - Version 10.2.0 to 11.1.0.7
Information in this document applies to any platform.

Symptoms

You have noticed that the DST changes that take effect in the database are not reflected when the timestamp is retrieved by an application using the JDBC driver.

 
Test Program
==========
 
import java.util.Date; 
import java.sql.*; 
import java.io.*; 
import java.text.*; 
import oracle.jdbc.pool.OracleDataSource; 
 
public class TimezoneTest { 
 
 public static void main(String[] args) throws Exception { 
 
  String username = "scott"; 
  String password = "tiger"; 
 
  OracleDataSource ds = new OracleDataSource(); 
  ds.setURL("jdbc:oracle:thin:@myhost.com:1521:orcl"); 
 
  Connection conn = null; 
  PreparedStatement statement = null; 
 
  try { 
 
   conn = ds.getConnection(username, password); 
 
   BufferedReader reader = new BufferedReader(new 
InputStreamReader(System.in)); 
 
   System.out.println("Press return to query the database time, q to quit"); 
   while(!reader.readLine().equals("q")) { 
 
    String sql = "select localtimestamp from dual"; 
    statement = conn.prepareStatement(sql); 
 
    ResultSet results = statement.executeQuery(); 
    results.next(); 
    Date dbTime = results.getTimestamp(1); 
    Date appTime = new Date(); 
 
    System.out.println("DB time: " + 
DateFormat.getTimeInstance(DateFormat.LONG).format(dbTime)); 
    System.out.println("App time: " + 
DateFormat.getTimeInstance(DateFormat.LONG).format(appTime)); 
 
   } 
  }finally{ 
   try { 
    if (conn != null) conn.close(); 
   }finally{ 
    if (statement != null) statement.close(); 
   } 
  } 
 } 
}
 

Steps-to-reproduce
================== 
1. set current timezone of your Windows PC to US/NewYork 
2. set system clock to 01:59:00 01 Nov 2009 
3. start the testCase application (Press enter to get another date-time 
reading by the application) 
4. wait a minute. Operating system should change time to apply Day Light 
Savings (system clock should be reverted to 01:00 AM) 
5. get another time reading from the application (press enter). It shows 
application time different from database time. 

We would expect that in step 5 database time matches the application time. 
Time discrepency is not balanced until application restart.

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