[英]Configure Datasource with timezone in jboss/weblogic server
我将通过每次获取数据库连接时重置数据库会话时区来处理 Web应用程序中的多个时区 。
代码如下:
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脚本来重置会话时区。
提前致谢
哇好
也许您可以尝试将日期和时间保存到支持时区的数据库列中,而不是每次连接时都扭曲数据源? 约定是将日期存储为UTC时间,然后在表示层中(或至少在检索后)进行时区转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.