【问题标题】:Old and beaten ORA-12705: Cannot access NLS data files or invalid environment specified and java Locale.setDefault()老旧的 ORA-12705: 无法访问 NLS 数据文件或指定的无效环境和 java Locale.setDefault()
【发布时间】:2011-01-13 21:19:07
【问题描述】:

我有一个让我发疯的问题 在我的笔记本电脑上,我在 ubuntu 上有 oracle-xe 10.2.0

数据库字符集:AMERICAN_AMERICA.AL32UTF8

NLS_LANG=AMERICAN_AMERICA.AL32UTF8

public static void main(String[] args) throws Exception {

//    Default locale before overwriting is ru_RU
//    Locale.setDefault(new Locale("EN"));
//
    Class.forName("oracle.jdbc.driver.OracleDriver");

    Connection conn = DriverManager.getConnection(
        "jdbc:oracle:thin:@localhost:1521:xe", "test", "test");
    try {
    // @machineName:port:SID, userid, password

      Statement stmt = conn.createStatement();
      try {
        ResultSet rset = stmt
            .executeQuery("select * from test");
        try {
          while (rset.next())
            System.out.println(rset.getString(1)); // Print col 1
        } finally {
          try {
            rset.close();
          } catch (Exception ignore) {
          }
        }
      } finally {
        try {
          stmt.close();
        } catch (Exception ignore) {
        }
      }
    } finally {
      try {
        conn.close();
      } catch (Exception ignore) {
      }
    }
  }

如果我评论 Locale.setDefault 我有一个 ORA-12705:无法访问 NLS 数据文件或无效环境指定异常(在这种情况下默认语言环境保持 ru_RU),但如果我将默认语言环境设置为 EN,那么一切都很好.

这意味着什么?为什么它使用 Locale.getDefault 值而不是 NLS_LANG,就像在每篇文章中都写过一样?

谢谢

【问题讨论】:

    标签: java oracle locale ora-12705


    【解决方案1】:

    请使用以下虚拟机选项: -Duser.region=US -Duser.language=en -Duser.country=US

    【讨论】:

      【解决方案2】:

      默认情况下,JDBC 语言环境由 JVM 语言环境确定,NLS_LANG 被忽略。另一种更改语言环境的方法是指定 -Duser.language 和 -Duser.country 命令行参数。

      【讨论】:

        猜你喜欢
        • 2011-10-13
        • 2018-09-20
        • 1970-01-01
        • 2013-07-28
        • 1970-01-01
        • 1970-01-01
        • 2023-03-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多