为 Oracle JDBC 瘦客户端设置语言

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/980692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 18:22:53  来源:igfitidea点击:

Set language for Oracle JDBC thin client

javaoraclejdbc

提问by sax

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

我想在实际创建 JDBC 连接之前为其指定语言。

For example if I specify wrong L/P credentials in

例如,如果我在

DriverManager.getConnection(url, user, password)    

I need to get ORAerror localized to the language I selected. I use Oracle thin client and setting NLS_LANGenvironmental variable did not work

我需要将ORA错误本地化为我选择的语言。我使用 Oracle 瘦客户端并且设置NLS_LANG环境变量不起作用

回答by Cedric Simon

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

这对我来说效果最好,如JDBC 瘦驱动程序的 NLS_LANG 设置中所述

 -Duser.language=en -Duser.region=US

回答by Adam Paynter

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

使用DriverManager.getConnection(String url, Properties info)方法可能会取得一些成功。

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

参数:

url- 格式为jdbc:subprotocol:subname的数据库 url

info- 作为连接参数的任意字符串标记/值对列表;通常至少应包括“用户”和“密码”属性

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

回答by Manish Singh

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.