正确的方法是使用
DelegatingDataSource,
OracleConnection从原始数据源检索对象,然后
OracleConnection.setSessionTimeZone()使用适当的参数进行调用。
C3P0代码如下所示:
private Object[] timeZoneArgs = new Object[] { "Europe/Berlin" };@Overridepublic Connection getConnection() throws SQLException { Connection conn = super.getConnection(); try { final Method setSessionTimeZoneMethod = OracleConnection.class.getMethod("setSessionTimeZone", String.class); final C3P0ProxyConnection castCon = (C3P0ProxyConnection) conn; castCon.rawConnectionOperation(setSessionTimeZoneMethod, C3P0ProxyConnection.RAW_CONNECTION, timeZoneArgs); return conn; } catch (Exception e) { log.error("setSessionTimeZone failed " + e.getMessage()); return conn; }}


