문제

I have a oracle procedure that takes date as a parameter and gets called by two different Java web apps, within the procedure I extract the day using to_char(date, 'd') from the date passed. I am unable to find out why the day returned by one app is different from other. I am using same ojdbc driver for both of the apps. Does it have anything to do with machine env variable these apps are running at?

Thanks

도움이 되었습니까?

해결책

Try to explicitly specify the timezone on both of your webapp containers by passing them the -Duser.timezone="America/New_York" VM argument (adjust per your timezone needs) when startingup them.

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();
    }

다른 팁

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.

try to check the default locale in JAVA/Oracle in both the applications.

I think that it may depend on the default locale set in JAVA.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top