1
我在我的web应用程序中通过每次获取数据库连接时重置数据库会话时区去handle multiple time zone。在jboss/weblogic服务器中配置带时区的数据源
代码如下:
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脚本来重置会话时区。
在此先感谢
如果日期列定义为TIMESTAMP WITH LOCAL TIME ZONE,那么Oracle将负责将日期转换为当前用户会话时区,不需要手动转换。所以我尝试每次将用户会话时区设置为数据库连接。 – Gopi