我有一个让我发疯的问题 在我的笔记本电脑上,我在ubuntu上有oracle-xe 10.2.0
DB Charset: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,就像每篇关于它的文章一样?
由于
答案 0 :(得分:0)
默认情况下,JDBC区域设置是从JVM区域设置确定的,NLS_LANG将被忽略。更改区域设置的另一种方法是指定-Duser.language和-Duser.country命令行参数。
答案 1 :(得分:0)
请使用以下VM选项: -Duser.region = US -Duser.language = en -Duser.country = US