开发者

Does java environment changes value of NLS_DATE_FORMAT parameter?

开发者 https://www.devze.com 2023-04-04 02:44 出处:网络
I have a unix and a linux server used as Database Server and Application Server Respectively. The Database is Oracle 10g and App Server is Weblogic 9.3 MP3 with jRockit 1.5 installed.

I have a unix and a linux server used as Database Server and Application Server Respectively. The Database is Oracle 10g and App Server is Weblogic 9.3 MP3 with jRockit 1.5 installed. I have a connection pool created in weblogic server.

I tried reading NLS_DATE_FORMAT from NLS_DATABASE_PARAMETERS, NLS_SESSION_PARAMETERS and NLS_INSTANCE_PARAMETERS table with four different way.

  1. Using sqlplus showing DD-MON-YYYY for all, as expected.
  2. A connection from pool in my web app the NLS_SESSION_PARAMETERS table show it as DD-MON-RR, and rest of table shows DD-MON-YYYY.
  3. 开发者_StackOverflow中文版
  4. A standalone java programs obtaining db connection directly, same result as in (3)
  5. Ran same program from my PC it showed same result as in (1) ie.DD-MON-YYYY for all.

I have not set NLS_LANG or NLS_DATE_FORMAT in any(on db server, on app server or on PC) of my environment any where. The init.ora has DD-MON-YYYY setting.

So what makes NLS_DATE_FORMAT different when doing through java code on server.


It's hard to say what's going on without seeing any of your code, but you shouldn't be relying on the database date format at all. You should be fetching date/timestamp values as objects - you can then format them however you want. Fundamentally you're not storing a string - you're storing a date or timestamp. A date which I might naturally write as "19/06/1976" might be written by someone else as "06-19-1976" - but both represent the same date.

It's like asking whether the databases uses hex or decimal to store integers: it doesn't do either, as far as we should care: it stores the integers themselves. Treat numbers as numbers, dates as dates, timestamps as timestamps etc, and when you want to display something to the user, choose the most appropriate format for that user.


As far as I know the JDBC driver will adjust the NLS settings to whatever Java's system property user.locale is set to.

So there is most probably a difference between the application server's locale setting and your lokal PC.


"the NLS_SESSION_PARAMETERS table show it as DD-MON-RR"

This format is, or at least ought to be, deprecated. It was introduced in the late nineties as a kludge for Y2K issues. Its purpose is to append a century to dates which are input as YY only. It uses a windowing algorithm to decide whether the YY needs a century of 19 or 20. The pivot is fixed - 49 - so as the calendar rolls on the allocations become increasingly unsatisfactory.

The fact that you are getting dates of 0011 instead of 2011 suggestions you have an ongoing Y2K issues. Space is no longer a problem, there really is no excuse for not explicitly specifying the full YYYY format.

0

精彩评论

暂无评论...
验证码 换一张
取 消