2

我有一个将日期作为参数并被两个不同的 Java Web 应用程序调用的 oracle 程序,在程序中我to_char(date, 'd')从传递的日期中提取使用的日期。我无法找出为什么一个应用程序返回的日期与其他应用程序不同。我为这两个应用程序使用相同的 ojdbc 驱动程序。它与这些应用程序运行的机器环境变量有什么关系吗?

谢谢

4

3 回答 3

2

this is because the first day of the week is not the same in all countries, for example in Europe the first day of the week is Monday while in the US it is Sunday. Consider:

SQL> select * from nls_session_parameters where parameter = 'NLS_TERRITORY';

PARAMETER                      VALUE
------------------------------ ----------------------------------------
NLS_TERRITORY                  AMERICA

SQL> select to_char(date '2010-12-07', 'D') from dual;

TO_CHAR(DATE'2010-12-07','D')
-----------------------------
3

SQL> alter session set nls_territory=FRANCE;

Session altered

SQL> select to_char(date '2010-12-07', 'D') from dual;

TO_CHAR(DATE'2010-12-07','D')
-----------------------------
2

Set the session parameter NLS_TERRITORY at the beginning of the procedure if it depends on it.

于 2010-12-07T13:46:40.707 回答
1

尝试在两个应用程序中检查 JAVA/Oracle 中的默认语言环境。

我认为这可能取决于 JAVA 中设置的默认语言环境。

于 2010-12-07T10:22:11.313 回答
1

尝试通过-Duser.timezone="America/New_York"在启动它们时传递 VM 参数(根据您的时区需要调整)来明确指定两个 webapp 容器的时区。

To address your comment, in the application level you could explicitly specify the desired timezone when calling your stored proc. For example:

CallableStatement statement = null;
Connection conn = null;

    try {
        conn = getYourConnection();
        Calendar dbCal = new GregorianCalendar(YOUR_DATABASE_TIMEZONE);

        String sql = "begin schema_name.package_name.stored_proc(var1=>?, " +
                "var2=>?); end;";

        statement = conn.prepareCall(sql);
        statement.setInt(1, something);
        statement.setTimestamp(2, yourDate.getTime(), dbCal);

        statement.execute();

        conn.commit();

    } finally {
        if (statement!=null) statement.close();
        if (conn!=null) conn.close();
    }
于 2010-12-07T12:27:01.113 回答