List of usage examples for org.apache.commons.dbcp2 PoolingDriver toString
public String toString()
From source file:za.co.wilderness.WildernessPoolingDriver.java
private void setupDriver() throws Exception { String jdbcDriverName = "com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource"; try {/*from www . j a va 2 s . c o m*/ java.lang.Class.forName(jdbcDriverName).newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { //System.out.println("Error when attempting to obtain DB Driver: " + jdbcDriverName + " on "+ new Date().toString() + e.getMessage()); logger.log(Level.SEVERE, "Error when attempting to obtain DB Driver: " + jdbcDriverName + " on " + new Date().toString(), e); throw new Exception(e); } ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(this.connectURI, this.properties); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); GenericObjectPoolConfig genConfig = new GenericObjectPoolConfig(); genConfig.setMaxIdle(this.config.getMaxIdle()); genConfig.setMaxTotal(this.config.getMaxActive()); genConfig.setMinIdle(this.config.getMinIdle()); genConfig.setMaxWaitMillis(this.config.getMaxWaitMillis()); genConfig.setTimeBetweenEvictionRunsMillis(5000); genConfig.setTestWhileIdle(true); ObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory, genConfig); // Set the factory's pool property to the owning pool poolableConnectionFactory.setPool(connectionPool); // // Finally, we create the PoolingDriver itself... // Class.forName("org.apache.commons.dbcp2.PoolingDriver"); PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:"); //System.out.println("Driver : " + driver.toString()); logger.log(Level.FINE, "Driver : " + driver.toString()); // // ...and register our pool with it. // driver.registerPool(EXTERNAL_SERVICE.name(), connectionPool); // // Now we can just use the connect string "jdbc:apache:commons:dbcp:example" // to access our pool of Connections. // }