Den korrekte måde er at bruge DelegatingDataSource
, hent OracleConnection
objekt fra den originale datakilde og kald OracleConnection.setSessionTimeZone()
med den relevante parameter.
C3P0-koden ser sådan ud:
private Object[] timeZoneArgs = new Object[] { "Europe/Berlin" };
@Override
public 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;
}
}