I want to setup a connection pool for a Oracle DB in a Helper class.
public class DbConnection {
// Data source for the pooled connection
private static Ora
You need you to use OracleDataSource (not OracleConnectionPoolDataSource) and set setConnectionCachingEnabled(true).
private static OracleDataSource ods = null;
...
static {
System.out.println("OracleDataSource Initialization");
try {
ods = new OracleDataSource();
ods.setConnectionCachingEnabled(true);
ods.setConnectionCacheName("mycache");
ods.setURL("jdbc:oracle:thin:@//server.local:1521/prod");
ods.setUser("scott");
ods.setPassword("tiger");
Properties cacheProps = new Properties();
cacheProps.setProperty("MinLimit", "1");
cacheProps.setProperty("MaxLimit", "4");
cacheProps.setProperty("InitialLimit", "1");
cacheProps.setProperty("ConnectionWaitTimeout", "5");
cacheProps.setProperty("ValidateConnection", "true");
ods.setConnectionCacheProperties(cacheProps);
}
catch (SQLException e) {
e.printStackTrace();
}
}
...
public static Connection getConnection()
throws SQLException {
return ods.getConnection();
}
Complete example here.