3

I want to specify language for the JDBC connection before it is actually created.

For example if I specify wrong L/P credentials in

DriverManager.getConnection(url, user, password)    

I need to get ORA error localized to the language I selected. I use Oracle thin client and setting NLS_LANG environmental variable did not work

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
sax
  • 808
  • 1
  • 12
  • 25

3 Answers3

5

This worked best for me, as stated in NLS_LANG setting for JDBC thin driver?

 -Duser.language=en -Duser.region=US
Community
  • 1
  • 1
Cedric Simon
  • 4,571
  • 4
  • 40
  • 52
  • 1
    This works because the JDBC thin driver looks into the Java Locale to extract the language and then changes the Database sessions language accordingly during connection establishment. The DB session's language is what's used to return the error message in the appropriate language. – Jean de Lavarene Jul 13 '17 at 09:01
1

As per documentation----

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.
Manish Singh
  • 3,463
  • 22
  • 21
1

You may have some success using the DriverManager.getConnection(String url, Properties info) method.

From the documentation:

Parameters:

url - a database url of the form jdbc:subprotocol:subname

info - a list of arbitrary string tag/value pairs as connection arguments; normally at least a "user" and "password" property should be included

Perhaps something like this may work:

String url = ...;
Properties info = new Properties();
info.setProperty("user", ...);
info.setProperty("password", ...);
info.setProperty("NLS_LANG", ...);
DriverManager.getConnection(url, info);
Community
  • 1
  • 1
Adam Paynter
  • 46,244
  • 33
  • 149
  • 164