oracle JDBC 瘦驱动程序的 NLS_LANG 设置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1079985/
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-10 01:59:53  来源:igfitidea点击:

NLS_LANG setting for JDBC thin driver?

oraclejdbcnlsora-12705

提问by dasp

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?

我使用的是精简版 Oracle JDBC 驱动程序 10.2.0 (ojdbc14.jar)。我想手动配置其 NLS_LANG 设置。有办法吗?

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

当前,它从 VM 变量 user.language(通过设置当前语言环境或从系统环境启动时自动设置)获取此设置。

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:

当用户将应用程序区域设置为 Oracle JDBC 驱动程序(例如 mk_MK)不支持的区域设置时,这是一个问题。在这种情况下,下次我获取连接时,我会收到以下异常:

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.

我可以在获取连接之前即时更改语言环境并来回切换回用户选择的语言环境,但这似乎不优雅且效率低下。

采纳答案by Adam Hawkes

The NLS_LANG settings are derived from the java.util.Locale . Therefore, you will need to make a call similar to this before connecting:

NLS_LANG 设置源自 java.util.Locale 。因此,您需要在连接之前进行类似的调用:

Locale.setDefault(Locale.<your locale here>);

回答by Micha? Niklas

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

另见: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:

对我来说,最好的回应是 FoxyBOA 调用 java 应用程序:

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

回答by Stanislav

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.

我正在解决同样的问题,发现瘦 jdbc Oracle 驱动程序不需要指定 NLS_LANG 或系统区域设置。但是当您连接到非英文数据库时,您将在类路径中拥有 orai18n.jar。

from Oracle? Database JDBC Developer's Guide and Reference

来自甲骨文?数据库 JDBC 开发人员指南和参考

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.

提供全球化支持

基本的 Java 存档 (JAR) 文件 ojdbc5.jar 和 ojdbc6.jar 包含为以下各项提供完整全球化支持所需的所有类:

  • 未作为 Oracle 对象或集合类型的数据成员检索或插入的 CHAR、VARCHAR、LONGVARCHAR 或 CLOB 数据的 Oracle 字符集。
  • 字符集 US7ASCII、WE8DEC、WE8ISO8859P1、WE8MSWIN1252 和 UTF8 的对象和集合的 CHAR 或 VARCHAR 数据成员。

要在对象或集合的 CHAR 或 VARCHAR 数据成员中使用任何其他字符集,您必须在应用程序的 CLASSPATH 环境变量中包含 orai18n.jar。

回答by svante

Invoking java with the following works for me :

使用以下方法调用 java 对我有用:

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

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

如果国家的“en”也会导致ORA-12705

回答by user416472

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.

您应该使用与 Oracle 10g 完全兼容并经过认证的旧 Oracle 9.2 JDBC 驱动程序。旧驱动程序不使用 ALTER SESSION SET NLS_LANGUAGE 命令。