Loading...

Check TimeZone on Linux host

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

We in Switzerland have the TimeZone Europe/Zurich. If you are using Java to connect to an Oracle DB, and the DB responds with an exception ORA-01882: timezone region not found it is most likely, that the connection problem is located on the linux host, in that the Java application runs. In my case it was rhel.

With an tzdata enhancement update RedHat delivers also the timezone Europe/Busingen.

Java thinks that the default timezone is Busingen instead of Zurich. Check with a simple java program.

import java.util.TimeZone;
public class Tz {
    public static void main(String[] args) {
        System.out.println(TimeZone.getDefault().getID());
    }
}

Compile and execute in /tmp folder

quang@cinhtau:/tmp> /opt/java/jdk1.8.0_51/bin/javac Tz.java
quang@cinhtau:/tmp> /opt/java/jdk1.8.0_51/bin/java Tz
Europe/Busingen

Check against table on Oracle DB instance

SELECT DISTINCT tzname FROM V$TIMEZONE_NAMES WHERE TZNAME LIKE 'Europe/B%';
"TZNAME"
"Europe/Bratislava"
"Europe/Bucharest"
"Europe/Brussels"
"Europe/Belgrade"
"Europe/Berlin"
"Europe/Budapest"
"Europe/Belfast"

There are several ways how Java retrieves the timezone:

  • Use the user.timezone system property, pass as param with -Duser.timezone="Europe/Zurich"
  • Use the TZ environment variable on the linux host ⇒ export TZ='Europe/Zurich', probably best in /etc/profile
  • Read the /etc/timezone file
  • Find the first file in /usr/share/zoneinfo/ that has the same contents.

/usr/share/zoneinfo/Europe/Busingen and /usr/share/zoneinfo/Europe/Zurich files have the same contents but Busingen is found first. Busingen is a german exclave in Switzerland, it has a separate timezone, because it doesn’t belong to Switzerland.

Setting /etc/timezone

root@cinhtau:~# cat /etc/timezone
Europe/Zurich

See alsoTime Zone Settings in the JRE.

As alternative the datasource configuration via JDBC can be set:

<connection-property name="oracle.jdbc.timezoneAsRegion">false</connection-property>

Or via local Java application directly

Properties jdbc = new Properties();
        jdbc.setProperty(oracle.jdbc.OracleConnection.CONNECTION_PROPERTY_TIMEZONE_AS_REGION, "Europe/Zurich");
Please remember the terms for blog comments.