ORA-01882: timezone region not found - oracle

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

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).

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.

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!!

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

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.

in eclipse go run - > run configuration
in there go to JRE tab in right side panels
in VM Arguments section paste this
-Duser.timezone=GMT
then Apply - > Run

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.

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.

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"

In Netbeans,
Right-click your project -> Properties
Go to Run (under Categories)
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.

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.

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.

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.

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);

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".

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 ?";

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
set timezone in /etc/sysconfig/clock e.g. set to ZONE="America/Los_Angeles"
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.

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

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.

Happens when you use the wrong version of OJDBC jar.
You need to use
11.2.0.4

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

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.

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);
}
}

Related

Spring Boot - Unable to connect Azure MySQL database

I am new in connecting azure MySQL database from Spring boot application.
Below is the snippet mentioned in application.properties
spring.datasource.url=jdbc:mysql://XXXX.mysql.database.azure.com:3306/MyDbName
spring.datasource.username= ******
spring.datasource.password= ******
I have faced the following exception
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Unknown system variable 'query_cache_size'
I have googled and somewhere it was mentioned that it is required to update the version of MySQLConnector to 8.0.13
Please help me find the solution.
Based on your exception , its not because of Azure mysql. Its because of system variable 'query_cache_size'. refer : java.sql.SQLException: Unknown system variable 'query_cache_size'
I too have met this bundle of joy on azure MySQL. As dvo mentions it places this variable in when it thinks it is under version 8.0.3.
From com.mysql.cj.NativeSession.java...
if (!versionMeetsMinimum(8, 0, 3)) {
queryBuf.append(", ##query_cache_size AS query_cache_size");
queryBuf.append(", ##query_cache_type AS query_cache_type");
}
But as my Azure MySQL version is 8.0.15 which matches my driver version then I suspect whilst the database may well be version 8 part of the stack the driver deals with is not.
Edit:
From https://learn.microsoft.com/en-us/azure/mysql/concepts-limits
Current known issues
MySQL server instance displays the wrong server version after connection is established. To get the correct server instance engine version, use the select version(); command.
So I'm guessing that this is the problem and as it stands Azure MySQL 8 will not work with the java mysql connector.
I'll probably look at building the connector myself and hard coding in the version number to 8.0.15. What joy.
Edit Edit:
Modified ServerVersion.java parseVersion(…) to return
return new ServerVersion(8, 0, 15);
Which works around the problem enough for me to carry on with my work.
It's a problem Microsoft should be fixing ASAP on their side.

Oracle XE 11g (windows 8) I can't connect to the Database (idle instance)

Hi I have problem with idle instance
When I trying:
sqlplus / as sysdba
I get result: Connected to an idle instance.
And when I try startup I get:
ORA-01078: failure in processing system parameters
ORA-01565 error in identifying file 'C:\oraclexe\app\oracle\product\11.2.0\server\dbs/spfileXE.ora
ORA-27041: unable to open file
ORA-04002: unable to open file
O/S-Error: (OS 2) File not found;
My system is Windows 8. Do you any idea how to solve it?
SOLUTION:
I have to startup using command:
startup pfile='<path to file>/init.ora'
and change all paths in init.ora where was
<ORACLE_BASE>
Thx for help
I've got that pain too.
To install Oracle XE you should login as local admin - NOT domain account.
This https://community.oracle.com/thread/2361291 made me happy :)
I just had the same problem.
You just have to start the setup to install the database as administrator.
After this and a reboot everything works fine.
I highly recommend reading the Oracle® Database 2 Day DBA manual, or hire a dba.
You are missing the init{ORACLE_SID}.ora, the parameter file which contains things like database name, controlfile locations. the init{ORACLE_SID}.ora is a text file that is edited with a regular text editor. This file can be converted to a spfile{ORACLE_SID}.ora that can be edited using a database instance. This is also a dynamic parameter file meaning that when you change parameters in an instance, the parameters can also be recorded in the spfile for later reuse.
For now add the db_name and control_files. Make sure that the contol_files parameter points to an existing controlfile[s]. If there are no existing control_file[s], just trash the initXE.ora, spfileXE.ora and start dbca, the Database Configuration Assistant and using that create a new database.

ORA-28040: No matching authentication protocol exception

I am trying to connect my grails project to Oracle databse(Oracle 12c) in windows(8) system. However, whenever I run my application I get following exception :
Caused by: org.apache.commons.dbcp.SQLNestedException:
Cannot create PoolableConnectionFactory (ORA-28040:
No matching authentication protocol)
Caused by:
java.sql.SQLException: ORA-28040:
No matching authentication protocol
According to internet suggestion I also tried editing my *.ora file but it is not working.
I added following snippet in sqlnet.ora file :
SQLNET.ALLOWED_LOGON_VERSION=10
SQLNET.ALLOWED_LOGON_VERSION_CLIENT=10
SQLNET.ALLOWED_LOGON_VERSION_SERVER=10
Here i tried assigning (10,11,12) but neither of them is working.
Can anyone please help me with this ?
I deleted the ojdbc14.jar file and used ojdbc6.jar instead and it worked for me
Here is some text I found at experts-exchange:
Bug 14575666
In 12.1, the default value for the SQLNET.ALLOWED_LOGON_VERSION
parameter has been updated to 11. This means that database clients
using pre-11g JDBC thin drivers cannot authenticate to 12.1 database
servers unless theSQLNET.ALLOWED_LOGON_VERSION parameter is set to the
old default of 8.
This will cause a 10.2.0.5 Oracle RAC database creation using DBCA to
fail with the ORA-28040: No matching authentication protocol error in
12.1 Oracle ASM and Oracle Grid Infrastructure environments.
Workaround: Set SQLNET.ALLOWED_LOGON_VERSION=8 in the
oracle/network/admin/sqlnet.ora file.
This except for adding the following to sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 8
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 8
If you get "ORA-01017: invalid username/password; logon denied" error, then you need to re-create your password.
I resolved this issue by using ojdbc8.jar.
Oracle 12c is compatible with ojdbc8.jar
I was using eclipse and after trying all the other answers it didn't work for me.
In the end, what worked for me was moving the ojdb7.jar to top in the Build Path. This occurs when multiple jars have conflicting same classes.
Select project in Project Explorer
Right click on Project -> Build Path -> Configure Build Path
Go to Order and Export tab and select ojdbc.jar
Click button TOP to move it to top
Very old question but providing some additional information which may help someone else. I also encountered same error and I was using ojdbc14.jar with 12.1.0.2 Oracle Database. On Oracle official web page this information is listed that which version supports which database drivers. Here is the link and it appears that with Oracle 12c and Java 7 or 8 the correct version is ojdbc7.jar.
In the ojdbc6.jar is for 11.2.0.4.
Except for adding the following to sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 8
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 8
I also added the following to both the Client and Server, which resolved my issue
SQLNET.AUTHENTICATION_SERVICES = (NONE)
Also see post
ORA-28040: No matching authentication protocol
Adding
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 8
is the perfect solution
sql.ora directory
..\product\12.1.0\dbhome_1\NETWORK\ADMIN
My Initial error is : ORA-28040: No matching authentication protocol exception
My DB version is 12.2 (Solaris) and client version is 11.2 ( windows). I have added below in both server and client sqlnet.ora
SQLNET.ALLOWED_LOGON_VERSION_CLIENT = 8
SQLNET.ALLOWED_LOGON_VERSION_SERVER = 8
while connecting, I have got invalid username and password hence I have recreated the password ( same password ) in database which is resolved my issue.
While for most cases replacing ojdbc driver jar will be the solution, my case was different.
If you are certain you are using correct ojdbc driver. Double check if you are actually connecting to the database you are thinking you are. In my case jdbc configuration (in Tomcat/conf) was pointing to different database that had different Oracle version.
just install ojdbc-full, That contains the 12.1.0.1 release.

What causes a JDBC Type 91 error?

I have a web app hosted on BEA Weblogic 10.x with an Oracle 10g database backend.
It works perfectly with one database, but when we make a clone of it and try to use a different WebLogic and Oracle instance we are getting this error:
ERROR - Problem initializing invocation tracking - disabling
tracking xxxxclass.BadTableMappingException: Database column
xxxxPeriodEnding in database yyyyyyy, table zzzzzzz has an
unknown type: JDBC Type 91.
We get it every time we do a query that involves a column of type DATE. There was no ORA-XXXX code in the message.
I can access the database using SQL*Plus using the same access and do selects and updates on the same tables with no errors.
The answer to this question is not just a simple description of what a type 91 error is (although that will help) but what could be causing this given the circumstances described above.
I am using ojdbc14.jar for JDBC on both instances of weblogic.
I have no idea about the error, but have you considered the jdbc jar version and more importantly if the oracle DB needs to be updated.
I faced very weird problems with oracle, and struggled for a while to find at the end that installing some patches for oracle would solve the problem.
Set oracle.jdbc.V8Compatible=true.
This remaps the oracle DATE type to a DATETIME time in JDBC. This parameter was missing on the new Weblogic server.

ORA-00604 ORA-12705

I am having this error in my j2ee web application.
java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1
ORA-12705: Cannot access NLS data files or invalid environment specified
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:283)
oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:278)
oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:785)
oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:376)
oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1353)
This project works in my colleagues' PCs... I mean this project works for them but when I asked for their project folder and imported it on my eclipse, when i run it i meet this error. The jar files are already packaged with the project folder.
I also created a simple j2ee project using hibernate but I had the same error.
I tried to ping the DB server and browse it using PL/SQL developer and I don't have any problem with it
Try following:
Check that NLS_LANG setting is correct. On windows it is in registry under \HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE.
Check that Oracle client software is correctly installed.
Check if there are multiple Oracle homes on that computer. In that case, find active one and check if it works.
Test with SQL*Plus if there is one installed. Sql Developer works because it has its own client installation.
Edit:
Regarding drivers, check this site: Oracle Instant Client. There you will find documentation on minimum drivers installation needed for JDBC access to Oracle. I don't know much about that because I use .Net.
Edit 2:
See this question: NLS_LANG setting for JDBC thin driver. There is same error as you have and problem was that default locale for NLS LANG was not defined. Quote:
The NLS_LANG settings are derived from the java.util.Locale . Therefore, you will need to make a call similar to this before connecting:
Locale.setDefault(Locale.<your locale here>);
I figured out that that you could pass that two params to your Java app to resolve the issue:
-Duser.country=en -Duser.language=en
You could configure the values at environment variable level as well (depends from your OS).
I had the same problem. The solution was to add the country and the language to sqldeveloper.conf
Please open the file:
\sqldeveloper\sqldeveloper\bin\sqldeveloper.conf
And add the following:
AddVMOption -Duser.language=en
AddVMOption -Duser.region=us
The above does the trick.
Reference: http://forum.oradba.net/showthread.php?t=423&langid=1
For Windows env, you need to change the System Locale and System Format to English/US.
How to change system locale?
I found solution, I just change the regional and language in my OS (windows 7), make sure it matches with the oracle regional and language.
Oracle JDBC driver implicitly executes following statement after opening new connection:
ALTER SESSION SET NLS_LANGUAGE='language' NLS_TERRITORY='territory'
In our case we had problems with Oracle XE 11g and default language/territory mappings embedded into JDBC driver: 'ru' locale was mapped to 'CIS' territory which is supported only by Oracle EE, but Oracle XE had 'RUSSIA' territory only.
Here is the way we fixed this:
-Doracle.jdbc.territoryMap="ru=RUSSIA;RU=RUSSIA"
There is option for NLS_LANGUAGE(we had no problems with defaults):
-Doracle.jdbc.languageMap="ru=RUSSIAN;RU=RUSSIAN"
Fixed: constant ru=RUSSIAN taken from class oracle.sql.converter.CharacterSetMetaData of java jdbc driver.
If you are compiling with intelljIDE I advise you add following options in VMoptions found in configurations model
AddVMOption -Duser.region=us.
First execute query:
select userenv('LANGUAGE') from dual;`
This will give oracle regional and language. Change the regional and language in OS, both should match.
check the JAVA_HOME system variable and verify that it is the same version you are using in your projects and programs
Changing the region settings and language of my machine helped to get away with this.
I changed region to United States and English (United States) as language.
If you are running a spring application just add Locale.setDefault(Locale.ENGLISH); at main class.
public static void main(String[] args) throws Exception
{
Locale.setDefault(Locale.ENGLISH);
SpringApplication.run(ApplicationName.class, args);
}

Resources