2

我有一个问题让我在笔记本电脑上发疯 我在 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,就像在每篇文章中都写过一样?

谢谢

4

2 回答 2

1

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

于 2015-10-18T15:54:20.157 回答
0

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

于 2011-02-02T13:47:02.960 回答