126

I'm accessing an Oracle Database from a java application, when I run my application I get the following error:

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not found

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
ndalama
  • 1,635
  • 3
  • 17
  • 15

23 Answers23

115

You may also try to check the version of the Oracle jdbc driver and Oracle database. Just today I had this issue when using ojdbc6.jar (version 11.2.0.3.0) to connect to an Oracle 9.2.0.4.0 server. Replacing it with ojdbc6.jar version 11.1.0.7.0 solved the issue.

I also managed to make ojdbc6.jar version 11.2.0.3.0 connect without error, by adding oracle.jdbc.timezoneAsRegion=false in file oracle/jdbc/defaultConnectionProperties.properties (inside the jar). Found this solution here (broken link)

Then, one can add -Doracle.jdbc.timezoneAsRegion=false to the command line, or AddVMOption -Doracle.jdbc.timezoneAsRegion=false in config files that use this notation.

You can also do this programmatically, e.g. with System.setProperty.

In some cases you can add the environment variable on a per-connection basis if that's allowed (SQL Developer allows this in the "Advanced" connection properties; I verified it to work when connecting to a database that doesn't have the problem and using a database link to a database which has).

Matteo Steccolini
  • 1,773
  • 1
  • 15
  • 21
  • 24
    I also managed to make ojdbc6.jar version 11.2.0.3.0 connect without error, by adding oracle.jdbc.timezoneAsRegion=false in file oracle/jdbc/defaultConnectionProperties.properties (inside the jar). Found this solution here: https://forums.oracle.com/forums/thread.jspa?threadID=1095807 – Matteo Steccolini Mar 15 '12 at 08:11
  • 33
    Lastly, one can add -Doracle.jdbc.timezoneAsRegion=false to the command line, or AddVMOption -Doracle.jdbc.timezoneAsRegion=false in config files that use this notation. – Matteo Steccolini Apr 29 '13 at 15:01
  • Thanks stmsat. It worked for me. I changed my ojdbc jar to 11.1.0.7.0 version in tomcat/lib directory and it started working :). – mdev Dec 30 '14 at 06:39
  • 1
    I am using maven to build and package(war) my project and deploy in Cloud Flare, is there any way setting this property can be done from *application.properties* file or from maven. – Ismail Nov 28 '19 at 11:10
  • Or maybe you can change system timezone, that worked for me (e.g. sudo timedatectl set-timezone you_zone) – kolle_86 Jun 30 '23 at 11:30
48

In a plain a SQL-Developer installation under Windows go to directory

C:\Program Files\sqldeveloper\sqldeveloper\bin

and add

AddVMOption -Duser.timezone=CET

to file sqldeveloper.conf.

Marcus Rickert
  • 4,138
  • 3
  • 24
  • 29
29

Error I got :

Error from db_connection.java -->> java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not found

ORA-00604: error occurred at recursive SQL level 1ORA-01882: timezone region not found

Prev code:

 public Connection getOracle() throws Exception {
     Connection conn = null;
     Class.forName("oracle.jdbc.driver.OracleDriver");
     conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:tap", "username", "pw");
     return conn;
}

new Code:

 public Connection getOracle() throws Exception {
     TimeZone timeZone = TimeZone.getTimeZone("Asia/Kolkata");
     TimeZone.setDefault(timeZone);
     Connection conn = null;
     Class.forName("oracle.jdbc.driver.OracleDriver");
     conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:tap", "username", "pw");
     return conn;
}

now it is working!!

  • I don't know why it did not like the default timezone 'Europe/Madrid'. Setting the default timezone to 'GMT' works. – fgui Jun 22 '16 at 09:57
24

Update the file oracle/jdbc/defaultConnectionProperties.properties in whatever version of the library (i.e. inside your jar) you are using to contain the line below:

oracle.jdbc.timezoneAsRegion=false
Babatunde Adeyemi
  • 14,360
  • 4
  • 34
  • 26
21

What happens is, that the JDBC client sends the timezone ID to the Server. The server needs to know that zone. You can check with

SELECT DISTINCT tzname FROM V$TIMEZONE_NAMES where tzname like 'Etc%';

I have some db servers which know about 'Etc/UTC' and 'UTC' (tzfile version 18) but others only know 'UTC' (tz version 11).

SELECT FILENAME,VERSION from V$TIMEZONE_FILE;

There is also different behavior on the JDBC client side. Starting with 11.2 the driver will sent the zone IDs if it is "known" to Oracle, whereas before it sent the time offset. The problem with this "sending of known IDs" is, that the client does not check what timezone version/content is present on the server but has its own list.

This is explained in Oracle Support Article [ID 1068063.1].

It seems it also depends on the Client OS, it was more likely that Etc/UTC fails with Ubuntu than RHEL or Windows. I guess this is due to some normalization but I haven't figured out what exactly.

eckes
  • 10,103
  • 1
  • 59
  • 71
17
  1. in eclipse go run - > run configuration

  2. in there go to JRE tab in right side panels

  3. in VM Arguments section paste this

    -Duser.timezone=GMT

  4. then Apply - > Run

Priyan at Dialog
  • 309
  • 1
  • 6
  • 16
12

I had this problem when running automated tests from a continuous integration server. I tried adding the VM argument "-Duser.timezone=GMT" to the build parameters, but that didn't solve the problem. However, adding the environment variable "TZ=GMT" did fix it for me.

Matt
  • 1,284
  • 14
  • 22
9

I ran into this problem with Tomcat. Setting the following in $CATALINA_BASE/bin/setenv.sh solved the issue:

JAVA_OPTS=-Doracle.jdbc.timezoneAsRegion=false

I'm sure that using one of the Java parameter suggestions from the other answers would work in the same way.

bonh
  • 2,863
  • 2
  • 33
  • 37
4

ERROR :

ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not found

Solution: CIM setup in Centos.

/opt/oracle/product/ATG/ATG11.2/home/bin/dynamoEnv.sh

Add this java arguments:

JAVA_ARGS="${JAVA_ARGS} -Duser.timezone=EDT"
Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Guna Sekaran
  • 553
  • 4
  • 5
3

In Netbeans,

  1. Right-click your project -> Properties
  2. Go to Run (under Categories)
  3. Enter -Duser.timezone=UTC or -Duser.timezone=GMT under VM Options.

Click Ok, then re-run your program.

Note: You can as well set to other timestones besides UTC & GMT.

Babatunde Adeyemi
  • 14,360
  • 4
  • 34
  • 26
3

If this problem is in JDeveloper: Change the project properties for both the model and the view project -> run/debug -> default profile -> edit add the following run option: -Duser.timezone=Asia/Calcutta

Make sure that the above time zone value is fetched from your database as follows:

select TZNAME from V$TIMEZONE_NAMES;

Along with that you'd want to check the time zone settings in your jdev.conf as well as in the JDeveloper -> Application Menu -> Default Project Propertes -> Run/Debug -> Default Profile -> Run Options.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
Mukul Rana
  • 31
  • 5
2

I also same faced similar issue.

Environment:

Linux, hibernate project, ojdbc6 driver while querying oracle 11g database.

Resolution

TZ parameter was not set in linux machine, that basically tell oracle about the timezone. So, After adding export statment "export TZ=UTC" at time of application start solved my problem.

UTC--> Change accorind to your timezone.

Community
  • 1
  • 1
2

I had the same problem when trying to make a connection on OBIEE to Oracle db. I changed my Windows timezone from (GMT+01:00) West Central Africa to (GMT+01:00) Brussels, Copenhagen, Madrid, Paris. Then I rebooted my computer and it worked just fine. Seems like Oracle was not able to recognize the west central Africa timezone.

yushaa yave
  • 145
  • 1
  • 9
2

This issue happens as the code which is trying to connect to db, has a timezone which is not in db. It can also be resolved by setting the time zone as below or any valid time zone available in oracle db. valid time zone which can be found select * from v$version;

System.setProperty("user.timezone", "America/New_York"); TimeZone.setDefault(null);

Uday Singh
  • 155
  • 1
  • 8
1

I too had the same problem when i tried to create connection in JDeveloper. Our server located in different timezone and hence it raised the below errors as:

ORA-00604: error occurred at recursive SQL level 1 

ORA-01882: timezone region not found

I referred many forums which asked to include timezone in the Java Options(Run/Debug/Profile) of Project properties and Default Project properties as -Duser.timezone="+02:00" bBut it didn't work for me. Finally the following solution worked for me.

Add the following line to the JDeveloper's configuration file (jdev.conf).

AddVMOption -Duser.timezone=UTC+02:00

The file is located in "<oracle installation root>\Middleware\jdeveloper\jdev\bin\jdev.conf".

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
Raj
  • 73
  • 2
  • 10
1

I was able to solve the same issue by setting the timezone in my linux system (Centos6.5).

Reposting from

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

  1. set timezone in /etc/sysconfig/clock e.g. set to ZONE="America/Los_Angeles"

  2. sudo ln -sf /usr/share/zoneinfo/America/Phoenix /etc/localtime

To figure out the timezone value try to

ls /usr/share/zoneinfo

and look for the file that represents your timezone.

Once you've set these reboot the machine and try again.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
adi-pradhan
  • 353
  • 2
  • 10
  • 2
    For me, making sure that /etc/sysconfig/clock and the /etc/localtime link were set properly was basically a prerequisite for solving the ORA-01882 issue. – David Keener Oct 14 '15 at 20:10
1

In my case I could get the query working by changing "TZR" with "TZD"..

String query = "select * from table1 to_timestamp_tz(origintime,'dd-mm-yyyy hh24:mi:ss TZD') between ?  and ?";
Laura Liparulo
  • 2,849
  • 26
  • 27
0

Facing the same issue using Eclipse and a distant Oracle Database, changing my system time zone to match the time zone of the database server fixed the problem. Re-start the machine after changing system time zone.

I hope this can help someone

S_intg
  • 182
  • 1
  • 10
0

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not found

For this type of error, just change your system time to your country's standard GMT format

e.g. Indian time zone is chennai,kolkata.

cf_en
  • 1,661
  • 1
  • 10
  • 18
0

Happens when you use the wrong version of OJDBC jar.

You need to use 11.2.0.4

simkeyur
  • 36
  • 1
  • 5
0

For my case, i set the timezone at my OS level (ubuntu) with this command.

timedatectl set-timezone {timezone}

For example,

timedatectl set-timezone Africa/Kampala
0

This might be a bit late but It may help someone. I encountered this issue while working on spring-boot application and failed to connect to the Oracle DB.

Error:

java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1

ORA-01882: timezone region not found

SELECT DBTIMEZONE FROM dual; -- This return: +00:00
timedatectl #The OS on the other hand returned correct time and timezone

Since I am not a system admin and not allowed to change system config, I had to apply a workaround in the codes.

spring.datasource.hikari.data-source-properties.oracle.jdbc.timezoneAsRegion=false
#Added the above into the application property file 

The working solution came from the below link

Working solution URL

Edit


After the DBA patched the oracle with the missing timezone patches, The above (...timezoneAsRegion=false) was no longer needed.

0

For Spring-Boot Application - // add below two lines

@SpringBootApplication
public class  Application {
  public static void main(String[] args) {
     // add below two lines
      System.out.println("Setting the timezone"+TimeZone.getTimeZone("GMT+9:00").getID());
      TimeZone.setDefault(TimeZone.getTimeZone("GMT+9:00"));
      SpringApplication.run(Application.class, args);
  }
}

Ritu Gupta
  • 2,249
  • 1
  • 18
  • 11