JDBC 瘦驱动程序的 NLS_LANG 设置?

2023-09-18数据库问题
9

本文介绍了JDBC 瘦驱动程序的 NLS_LANG 设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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

当用户将应用程序语言环境切换到 Oracle JDBC 驱动程序(例如 mk_MK)不支持的语言环境时,这是一个问题.在这种情况下,下次我获取连接时会出现以下异常:

<前>ORA-00604: 递归 SQL 级别 1 发生错误ORA-12705: 无法访问 NLS 数据文件或指定的环境无效

我可以在获取连接之前即时更改区域设置,然后来回切换回用户选择的区域设置,但这似乎不优雅且效率低下.

解决方案

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

Locale.setDefault(Locale.<您的语言环境>);

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?

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

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:

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.

解决方案

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

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

这篇关于JDBC 瘦驱动程序的 NLS_LANG 设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

如何在MySQL中为每个组选择第一行?
How to select the first row for each group in MySQL?(如何在MySQL中为每个组选择第一行?)...
2024-04-16 数据库问题
13

MySQL - 获取最低值
MySQL - Fetching lowest value(MySQL - 获取最低值)...
2024-04-16 数据库问题
8

在 cmakelist.txt 中添加和链接 mysql 库
Add and link mysql libraries in a cmakelist.txt(在 cmakelist.txt 中添加和链接 mysql 库)...
2024-04-16 数据库问题
41

考勤数据库的良好数据库设计(架构)是什么?
What is a good database design (schema) for a attendance database?(考勤数据库的良好数据库设计(架构)是什么?)...
2024-04-16 数据库问题
7