NLS_LANG setting for JDBC thin driver?
Asked Answered
S

5

28

I am using the thin Oracle JDBC driver ver 10.2.0 (ojdbc14.jar). I would like to configure its NLS_LANG setting manually. Is there a way?

Currently it fetches this setting from the VM variable user.language (which is set automatically by setting the current locale, or on startup from the system environment).

This is a problem when the users switch the application locale to a one that is unsupported by the Oracle JDBC driver (e.g. mk_MK). In this case, the next time I fetch a connection I get the following exception:

ORA-00604: error occurred at recursive SQL level 1
ORA-12705: Cannot access NLS data files or invalid environment specified

I can change the locale on the fly just before I fetch the connection and switch back to the user's selected one back and forth, but this seems unelegant and unefficient.

Sportswoman answered 3/7, 2009 at 16:6 Comment(0)
S
16

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>);
Shakedown answered 20/8, 2009 at 12:59 Comment(2)
Yes, this is exactly what I did end up doing. It works fine, but it is not very pretty. Thanks!Sportswoman
God Tier answer. Use Locale.US to mimic the AMERICAN language settings.Peale
C
20

See also: https://serverfault.com/questions/63216/ora-12705-cannot-access-nls-data-files-or-invalid-environment-specified/64536

For me the best response was by FoxyBOA to invoke java app with:

-Duser.country=en -Duser.language=en
Cherian answered 19/11, 2010 at 11:56 Comment(4)
Funny. Vote for own answer cross-posted here :DSoma
+1 as it's a lot less invasive than the currently accepted answer.Botnick
Thanks. Worked for SQLDeveloper and also for web-logic data-sourceMeemeece
This one solved my problem: -Duser.language=en -Duser.region=USCamillacamille
S
16

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>);
Shakedown answered 20/8, 2009 at 12:59 Comment(2)
Yes, this is exactly what I did end up doing. It works fine, but it is not very pretty. Thanks!Sportswoman
God Tier answer. Use Locale.US to mimic the AMERICAN language settings.Peale
H
11

I was fighting the same problem and found out that thin jdbc Oracle drivers do not require NLS_LANG or system locale to be specified. But when you connect to non-english databases you are to have orai18n.jar in the classpath.

from Oracle® Database JDBC Developer’s Guide and Reference

Providing Globalization Support

The basic Java Archive (JAR) files, ojdbc5.jar and ojdbc6.jar, contain all the necessary classes to provide complete globalization support for:

  • Oracle character sets for CHAR, VARCHAR, LONGVARCHAR, or CLOB data that is not being retrieved or inserted as a data member of an Oracle object or collection type.
  • CHAR or VARCHAR data members of object and collection for the character sets US7ASCII, WE8DEC, WE8ISO8859P1, WE8MSWIN1252, and UTF8.

To use any other character sets in CHAR or VARCHAR data members of objects or collections, you must include orai18n.jar in the CLASSPATH environment variable of your application.

Homolographic answered 6/4, 2010 at 14:6 Comment(0)
B
7

Invoking java with the following works for me :

-Duser.country=us -Duser.language=en

if "en" for country also causes ORA-12705.

Baucom answered 28/8, 2012 at 12:57 Comment(1)
That is because there is no "EN" country. There are: US, GB, and many others that have English as official languageAlee
I
1

You should use the old Oracle 9.2 JDBC driver that is fully compatible and certified with Oracle 10g. The old driver does not use ALTER SESSION SET NLS_LANGUAGE commands.

Iila answered 23/11, 2010 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.