【问题标题】:Configure Datasource with timezone in jboss/weblogic server在 jboss/weblogic 服务器中使用时区配置数据源
【发布时间】:2016-02-25 22:12:32
【问题描述】:

我将通过每次获得数据库连接时重置数据库会话时区来在我的 Web 应用程序中访问 handle multiple time zone

代码如下:

public Connection getConnection(GmDNSNamesEnum enDNSName) throws AppError
    {
         ...   
         DataSource ds = (DataSource) ic.lookup(enDNSName.getDNSName());
            conn = ds.getConnection();
            conn.setAutoCommit(false);
            setTimeZone(strTimeZone);
        ...
        return conn;
    }




private void setTimeZone(String strTimeZone){
     Statement stmt = null;
     if(conn != null) {
     try{
     stmt = conn.createStatement();
         stmt.execute("alter session set time_zone=\'" + strTimeZone+"\'");
     } catch (Exception e)
         {
         String strErrorMsg = GmCommonClass.getExceptionStackTrace(e);
             log.error("Exception e "+strErrorMsg);
         throw new AppError(e);
         }
     }
    }

有没有其他方法可以设置数据库会话时区?

现在,我正在寻找在 jboss/weblogic 服务器中配置不同时区的数据源,并使用特定于用户时区的适当数据源,而不是每次都通过执行 alter session 脚本来重置会话时区。

提前致谢

【问题讨论】:

    标签: jdbc oracle11g timezone weblogic jboss7.x


    【解决方案1】:

    哇哦。

    也许您可以尝试将日期和时间保存到可识别时区的数据库列中,而不是每次连接时都扭曲数据源?惯例是以 UTC 时间存储日期,然后在表示层(或至少在检索后)中进行时区转换。

    【讨论】:

    • 如果 Date 列定义为 TIMESTAMP WITH LOCAL TIME ZONE,那么 Oracle 将负责将日期转换为当前用户会话时区,不需要手动转换。所以我每次都尝试将用户会话时区设置为数据库连接。
    猜你喜欢
    • 2017-12-10
    • 2012-12-19
    • 1970-01-01
    • 2021-07-10
    • 2014-12-03
    • 2012-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多