【发布时间】: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