在webapp中从java设置Oracle NLS_LANGUAGE [英] Set Oracle NLS_LANGUAGE from java in a webapp

查看:141
本文介绍了在webapp中从java设置Oracle NLS_LANGUAGE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JDBC的理解是它根据JVM的默认Locale自动设置Oracle NLS_LANGUAGE / NLS_TERRITORY会话参数。这对于独立的swing应用程序来说很方便,但对于java webapp似乎毫无用处。我能想到的唯一解决方案是在实际进行数据库查询之前专门设置会话参数,类似于:

My understanding of JDBC is that it automatically sets the Oracle NLS_LANGUAGE/NLS_TERRITORY session parameters based on the default Locale of the JVM. This is handy for a stand-alone swing app, but seems useless for a java webapp. The only solution I can come up with is to specifically set the session parameters right before actually doing a database query, something similar to:

Connection c = // However you get it.
Statement s = c.createStatement();
s.execute("alter session set NLS_LANGUAGE = 'SPANISH'");
// Do actual query here

我的问题:


  1. 这是从webapp设置Oracle语言/国家/地区参数的最佳方式吗?

  2. 由于Oracle参数采用语言名称而非比代码,是否有从java / ISO语言代码到Oracle语言名称的映射?例如,我可以使用Locale.getDisplayLanguage()并且是安全的吗?


推荐答案

可以依赖在您的架构上。

Can depend on your architecture.

有些地方选择在一个数据库中拥有多个地理位置本地的网络应用程序(即法国一个,英国一个,西班牙一个)。

Some places opt to have multiple geographically local web-apps against a single database (ie one in the France, one in the UK, one in Spain).

或者您从数据库中以计算机格式提取数据(例如日期,数字),并让网络应用程序将其转换为最终用户的偏好(或者可能如果您没有用户登录,则根据浏览器信息。)

Or you pull data (eg dates, numbers) in 'computer' format from the database and have the web-app convert it to the end-user's preferences (or possibly based on browser information if you don't have user logins).

或者您为不同的地区设置了单独的连接池。

Or you have separate connection pools for different 'territories'.

请记住,更改地区的查询可能会影响索引使用和排序

Bear in mind that queries changing territories can affect index usage and sorting.

这篇关于在webapp中从java设置Oracle NLS_LANGUAGE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆