Java Code Examples for org.apache.commons.dbcp2.BasicDataSource#setUsername()
The following examples show how to use
org.apache.commons.dbcp2.BasicDataSource#setUsername() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceFactory.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
private static void external_dbcp2() throws Exception { for (ExternalDataSource ds : Config.externalDataSources()) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(ds.getDriverClassName()); dataSource.setUrl(ds.getUrl()); dataSource.setInitialSize(0); dataSource.setMinIdle(0); dataSource.setMaxTotal(ds.getMaxTotal()); dataSource.setMaxIdle(ds.getMaxTotal()); dataSource.setTestOnCreate(false); dataSource.setTestWhileIdle(false); dataSource.setTestOnReturn(false); dataSource.setTestOnBorrow(false); dataSource.setUsername(ds.getUsername()); dataSource.setPassword(ds.getPassword()); String name = Config.externalDataSources().name(ds); new Resource(Config.RESOURCE_JDBC_PREFIX + name, dataSource); } }
Example 2
Source File: SinkToMySQL.java From flink-learning with Apache License 2.0 | 6 votes |
private static Connection getConnection(BasicDataSource dataSource) { dataSource.setDriverClassName("com.mysql.jdbc.Driver"); //注意,替换成自己本地的 mysql 数据库地址和用户名、密码 dataSource.setUrl("jdbc:mysql://localhost:3306/test"); dataSource.setUsername("root"); dataSource.setPassword("root123456"); //设置连接池的一些参数 dataSource.setInitialSize(10); dataSource.setMaxTotal(50); dataSource.setMinIdle(2); Connection con = null; try { con = dataSource.getConnection(); log.info("创建连接池:{}", con); } catch (Exception e) { log.error("-----------mysql get connection has exception , msg = {}", e.getMessage()); } return con; }
Example 3
Source File: AbstractMysqlHandler.java From adt with Apache License 2.0 | 6 votes |
public AbstractMysqlHandler() throws Exception{ shardCount = Integer.parseInt(System.getProperty(PROP_SHARD_CNT)); for(int i=0; i<shardCount; i++){ final BasicDataSource ds = new BasicDataSource(); ds.setMaxTotal(1024); ds.setMaxIdle(1024); ds.setMinIdle(0); ds.setUrl(System.getProperty(String.format(PROP_SHARD_URL, i))); ds.setUsername(System.getProperty(String.format(PROP_SHARD_USERNAME, i))); ds.setPassword(System.getProperty(String.format(PROP_SHARD_PASSWORD, i))); dataSourceList.add(ds); } // final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); // scriptEngine = scriptEngineManager.getEngineByName(SCRIPT_ENGINE_NAME); // scriptEngine.eval(System.getProperty(PROP_SCRIPT)); }
Example 4
Source File: MultiJdbcSchemaJoinTest.java From calcite with Apache License 2.0 | 6 votes |
/** Tests {@link org.apache.calcite.adapter.jdbc.JdbcCatalogSchema}. */ @Test void test3() throws SQLException { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(TempDb.INSTANCE.getUrl()); dataSource.setUsername(""); dataSource.setPassword(""); final JdbcCatalogSchema schema = JdbcCatalogSchema.create(null, "", dataSource, "PUBLIC"); assertThat(schema.getSubSchemaNames(), is(Sets.newHashSet("INFORMATION_SCHEMA", "PUBLIC", "SYSTEM_LOBS"))); final CalciteSchema rootSchema0 = CalciteSchema.createRootSchema(false, false, "", schema); final Driver driver = new Driver(); final CalciteJdbc41Factory factory = new CalciteJdbc41Factory(); final String sql = "select count(*) as c from information_schema.schemata"; try (Connection connection = factory.newConnection(driver, factory, "jdbc:calcite:", new Properties(), rootSchema0, null); Statement stmt3 = connection.createStatement(); ResultSet rs = stmt3.executeQuery(sql)) { assertThat(CalciteAssert.toString(rs), equalTo("C=3\n")); } }
Example 5
Source File: DaoEnvTestSpringModuleConfig.java From herd with Apache License 2.0 | 6 votes |
/** * Get a new herd data source based on an in-memory HSQLDB database. This data source is used for loading the configuration table as an environment property * source as well as for the JPA entity manager. It will therefore create/re-create the configuration table which is required for the former. It also * inserts required values for both scenarios. * * @return the test herd data source. */ @Bean public static DataSource herdDataSource() { // Create and return a data source that can connect directly to a JDBC URL. BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(org.h2.Driver.class.getName()); basicDataSource.setUsername(""); basicDataSource.setPassword(""); basicDataSource.setUrl("jdbc:h2:mem:herdTestDb"); // Create and populate the configuration table. // This is needed for all data source method calls since it is used to create the environment property source which happens before // JPA and other non-static beans are initialized. ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator(); resourceDatabasePopulator.addScript(new ClassPathResource("createConfigurationTableAndData.sql")); DatabasePopulatorUtils.execute(resourceDatabasePopulator, basicDataSource); // This is what the DataSourceInitializer does. return basicDataSource; }
Example 6
Source File: CompatCreator.java From dremio-oss with Apache License 2.0 | 5 votes |
public static DataSource getDataSource(ConnectionPoolDataSource cpds, String driver, String url, String username, String password) throws SQLException { Preconditions.checkNotNull(driver); if (cpds != null) { // Configuration supplied a driver-specific CPDS. return newSharedDataSource(cpds); } // Use the ConnectionPoolDataSource supplied by Apache DBCP. final BasicDataSource source = new BasicDataSource(); // unbounded number of connections since we could have hundreds of queries running many threads simultaneously. source.setMaxTotal(Integer.MAX_VALUE); source.setTestOnBorrow(true); source.setValidationQueryTimeout(1); source.setDriverClassName(driver); source.setUrl(url); if (username != null) { source.setUsername(username); } if (password != null) { source.setPassword(password); } return source; }
Example 7
Source File: DataSourceDecoratorAutoConfigurationTests.java From spring-boot-data-source-decorator with Apache License 2.0 | 5 votes |
@Bean public DataSource secondDataSource() { BasicDataSource pool = new BasicDataSource(); pool.setDriverClassName("org.hsqldb.jdbcDriver"); pool.setUrl("jdbc:hsqldb:target/db2"); pool.setUsername("sa"); return pool; }
Example 8
Source File: AppConfig.java From Spring-Framework-Essentials with MIT License | 5 votes |
@Bean(name = "dataSource") @Profile("prod") public DataSource dataSourceForProd() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(env.getProperty("db.driver")); dataSource.setUrl(env.getProperty("db.url")); dataSource.setUsername(env.getProperty("db.user")); dataSource.setPassword(env.getProperty("db.pass")); return dataSource; }
Example 9
Source File: ConfigCenterTest.java From shardingsphere with Apache License 2.0 | 5 votes |
private DataSource createDataSource(final String name) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName("com.mysql.jdbc.Driver"); result.setUrl("jdbc:mysql://localhost:3306/" + name); result.setUsername("root"); result.setPassword("root"); return result; }
Example 10
Source File: Main.java From jweb-cms with GNU Affero General Public License v3.0 | 5 votes |
public static void main(String[] args) throws LiquibaseException, SQLException, IOException, ParserConfigurationException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:mysql://localhost:3306/main?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"); dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); dataSource.setUsername("root"); java.sql.Connection connection = dataSource.getConnection(); Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); Liquibase liquibase = new Liquibase("db-changes.yml", new ClassLoaderResourceAccessor(), database); CatalogAndSchema catalogAndSchema = new CatalogAndSchema(null, "main"); DiffToChangeLog changeLog = new DiffToChangeLog(new DiffOutputControl(false, false, true, null)); liquibase.generateChangeLog(catalogAndSchema, changeLog, new PrintStream(new FileOutputStream("./change-logs.yml")), new YamlChangeLogSerializer(), snapTypes()); }
Example 11
Source File: QueryTest.java From search-commons with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:mysql://127.0.0.1:3306?characterEncoding=UTF-8"); dataSource.setUsername("root"); dataSource.setPassword("123456"); queryRunner = new DefaultQueryRunner(dataSource); }
Example 12
Source File: AbstractSpringJUnitTest.java From shardingsphere with Apache License 2.0 | 5 votes |
private DataSource createDataSource(final String dataSetFile) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(org.h2.Driver.class.getName()); result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL", getFileName(dataSetFile))); result.setUsername("sa"); result.setPassword(""); result.setMaxTotal(100); return result; }
Example 13
Source File: SpringTest.java From java-jdbc with Apache License 2.0 | 5 votes |
private static BasicDataSource getDataSource(boolean traceWithActiveSpanOnly, List<String> ignored) { String ignoreForTracing = TestUtil.buildIgnoredString(ignored); BasicDataSource dataSource = new BasicDataSource(); dataSource .setUrl("jdbc:tracing:h2:mem:spring?" + ignoreForTracing + "traceWithActiveSpanOnly=" + traceWithActiveSpanOnly); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
Example 14
Source File: DbTests.java From morpheus-core with Apache License 2.0 | 5 votes |
/** * Returns a newly created DataSource based on Apache Commons DBCP * @param dbType the database type * @param path the path to the database file * @return the newly created data source */ private static DataSource createDataSource(DbType dbType, File path) { System.out.println("Creating DataSource for " + path.getAbsolutePath()); path.getParentFile().mkdirs(); final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDefaultAutoCommit(true); switch (dbType) { case H2: dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl("jdbc:h2://" + path.getAbsolutePath()); dataSource.setUsername("sa"); return dataSource; case HSQL: dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl("jdbc:hsqldb:" + path.getAbsolutePath()); dataSource.setUsername("sa"); return dataSource; case SQLITE: dataSource.setDriverClassName("org.sqlite.JDBC"); dataSource.setUrl("jdbc:sqlite:" + path.getAbsolutePath()); dataSource.setUsername(""); dataSource.setPassword(""); return dataSource; } return dataSource; }
Example 15
Source File: JDBCSessionDataStorageTest.java From pippo with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("org.h2.Driver"); bds.setUrl("jdbc:h2:mem:test;INIT=runscript from 'src/test/resources/create.sql'"); bds.setUsername("sa"); bds.setPassword("sa"); dataSource = bds; }
Example 16
Source File: PgConnectionHelper.java From pg-index-health with Apache License 2.0 | 5 votes |
private static void setCommonProperties(@Nonnull final BasicDataSource dataSource, @Nonnull final String userName, @Nonnull final String password) { dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUsername(userName); dataSource.setPassword(password); dataSource.setValidationQuery("select 1"); dataSource.setMaxTotal(1); dataSource.setMaxIdle(1); dataSource.setMaxOpenPreparedStatements(1); }
Example 17
Source File: DynamicJdbcIO.java From DataflowTemplates with Apache License 2.0 | 4 votes |
@VisibleForTesting DataSource buildDatasource() { BasicDataSource basicDataSource = new BasicDataSource(); if (getDriverClassName() != null) { if (getDriverClassName().get() == null) { throw new RuntimeException("Driver class name is required."); } basicDataSource.setDriverClassName(getDriverClassName().get()); } if (getUrl() != null) { if (getUrl().get() == null) { throw new RuntimeException("Connection url is required."); } basicDataSource.setUrl(getUrl().get()); } if (getUsername() != null) { basicDataSource.setUsername(getUsername().get()); } if (getPassword() != null) { basicDataSource.setPassword(getPassword().get()); } if (getConnectionProperties() != null && getConnectionProperties().get() != null) { basicDataSource.setConnectionProperties(getConnectionProperties().get()); } /** * Since the jdbc connection connection class might have dependencies that are not available * to the template, we will localize the user provided dependencies from GCS and create a new * {@link URLClassLoader} that is added to the {@link * BasicDataSource#setDriverClassLoader(ClassLoader)} */ if (getDriverJars() != null) { ClassLoader urlClassLoader = getNewClassLoader(getDriverJars()); basicDataSource.setDriverClassLoader(urlClassLoader); } // wrapping the datasource as a pooling datasource DataSourceConnectionFactory connectionFactory = new DataSourceConnectionFactory(basicDataSource); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, null); GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig(); poolConfig.setMaxTotal(1); poolConfig.setMinIdle(0); poolConfig.setMinEvictableIdleTimeMillis(10000); poolConfig.setSoftMinEvictableIdleTimeMillis(30000); GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory, poolConfig); poolableConnectionFactory.setPool(connectionPool); poolableConnectionFactory.setDefaultAutoCommit(false); poolableConnectionFactory.setDefaultReadOnly(false); PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool); return poolingDataSource; }
Example 18
Source File: DataSharding.java From blog with BSD 2-Clause "Simplified" License | 4 votes |
public static void main(String[] args) { // 配置真实数据源 Map<String, DataSource> dataSourceMap = new HashMap<>(); // 配置第一个数据源 BasicDataSource dataSource1 = new BasicDataSource(); dataSource1.setDriverClassName("com.mysql.jdbc.Driver"); dataSource1.setUrl("jdbc:mysql://localhost:3306/ds0"); dataSource1.setUsername("root"); dataSource1.setPassword("root"); dataSourceMap.put("ds0", dataSource1); // 配置第二个数据源 BasicDataSource dataSource2 = new BasicDataSource(); dataSource2.setDriverClassName("com.mysql.jdbc.Driver"); dataSource2.setUrl("jdbc:mysql://localhost:3306/ds1"); dataSource2.setUsername("root"); dataSource2.setPassword("root"); dataSourceMap.put("ds1", dataSource2); // 配置Order表规则 TableRuleConfiguration orderTableRuleConfig = new TableRuleConfiguration("t_order", "ds${0..1}.t_order${0..1}"); // 配置分库 + 分表策略 orderTableRuleConfig.setDatabaseShardingStrategyConfig( new InlineShardingStrategyConfiguration("user_id", "ds${user_id % 2}")); orderTableRuleConfig.setTableShardingStrategyConfig( new InlineShardingStrategyConfiguration("order_id", "t_order${order_id % 2}")); // 配置分片规则 ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTableRuleConfigs().add(orderTableRuleConfig); // 省略配置order_item表规则... // ... // 获取数据源对象 try { DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig, new Properties()); Connection conn = dataSource.getConnection(); String sql = "insert into t_order (user_id,order_id) values (?,?)"; PreparedStatement preparedStatement = conn.prepareStatement(sql); for (int i = 1; i <= 10; i++) { preparedStatement.setInt(1, 10 + i); preparedStatement.setInt(2, 1001 + i); preparedStatement.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } }
Example 19
Source File: HadoopDBCPConnectionPool.java From nifi with Apache License 2.0 | 4 votes |
/** * Configures connection pool by creating an instance of the * {@link BasicDataSource} based on configuration provided with * {@link ConfigurationContext}. * * This operation makes no guarantees that the actual connection could be * made since the underlying system may still go off-line during normal * operation of the connection pool. * * @param context * the configuration context * @throws InitializationException * if unable to create a database connection */ @OnEnabled public void onEnabled(final ConfigurationContext context) throws IOException { // Get Configuration instance from specified resources final String configFiles = context.getProperty(HADOOP_CONFIGURATION_RESOURCES).evaluateAttributeExpressions().getValue(); final Configuration hadoopConfig = getConfigurationFromFiles(configFiles); // Add any dynamic properties to the HBase Configuration for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) { final PropertyDescriptor descriptor = entry.getKey(); if (descriptor.isDynamic()) { hadoopConfig.set(descriptor.getName(), context.getProperty(descriptor).evaluateAttributeExpressions().getValue()); } } // If security is enabled then determine how to authenticate based on the various principal/keytab/password options if (SecurityUtil.isSecurityEnabled(hadoopConfig)) { final String explicitPrincipal = context.getProperty(kerberosProperties.getKerberosPrincipal()).evaluateAttributeExpressions().getValue(); final String explicitKeytab = context.getProperty(kerberosProperties.getKerberosKeytab()).evaluateAttributeExpressions().getValue(); final String explicitPassword = context.getProperty(kerberosProperties.getKerberosPassword()).getValue(); final KerberosCredentialsService credentialsService = context.getProperty(KERBEROS_CREDENTIALS_SERVICE).asControllerService(KerberosCredentialsService.class); final String resolvedPrincipal; final String resolvedKeytab; if (credentialsService != null) { resolvedPrincipal = credentialsService.getPrincipal(); resolvedKeytab = credentialsService.getKeytab(); } else { resolvedPrincipal = explicitPrincipal; resolvedKeytab = explicitKeytab; } if (resolvedKeytab != null) { kerberosUser = new KerberosKeytabUser(resolvedPrincipal, resolvedKeytab); getLogger().info("Security Enabled, logging in as principal {} with keytab {}", new Object[] {resolvedPrincipal, resolvedKeytab}); } else if (explicitPassword != null) { kerberosUser = new KerberosPasswordUser(resolvedPrincipal, explicitPassword); getLogger().info("Security Enabled, logging in as principal {} with password", new Object[] {resolvedPrincipal}); } else { throw new IOException("Unable to authenticate with Kerberos, no keytab or password was provided"); } ugi = SecurityUtil.getUgiForKerberosUser(hadoopConfig, kerberosUser); getLogger().info("Successfully logged in as principal " + resolvedPrincipal); } else { getLogger().info("Simple Authentication"); } // Initialize the DataSource... final String dbUrl = context.getProperty(DATABASE_URL).evaluateAttributeExpressions().getValue(); final String driverName = context.getProperty(DB_DRIVERNAME).evaluateAttributeExpressions().getValue(); final String user = context.getProperty(DB_USER).evaluateAttributeExpressions().getValue(); final String passw = context.getProperty(DB_PASSWORD).evaluateAttributeExpressions().getValue(); final Integer maxTotal = context.getProperty(MAX_TOTAL_CONNECTIONS).evaluateAttributeExpressions().asInteger(); final String validationQuery = context.getProperty(VALIDATION_QUERY).evaluateAttributeExpressions().getValue(); final Long maxWaitMillis = extractMillisWithInfinite(context.getProperty(MAX_WAIT_TIME).evaluateAttributeExpressions()); final Integer minIdle = context.getProperty(MIN_IDLE).evaluateAttributeExpressions().asInteger(); final Integer maxIdle = context.getProperty(MAX_IDLE).evaluateAttributeExpressions().asInteger(); final Long maxConnLifetimeMillis = extractMillisWithInfinite(context.getProperty(MAX_CONN_LIFETIME).evaluateAttributeExpressions()); final Long timeBetweenEvictionRunsMillis = extractMillisWithInfinite(context.getProperty(EVICTION_RUN_PERIOD).evaluateAttributeExpressions()); final Long minEvictableIdleTimeMillis = extractMillisWithInfinite(context.getProperty(MIN_EVICTABLE_IDLE_TIME).evaluateAttributeExpressions()); final Long softMinEvictableIdleTimeMillis = extractMillisWithInfinite(context.getProperty(SOFT_MIN_EVICTABLE_IDLE_TIME).evaluateAttributeExpressions()); dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverName); dataSource.setDriverClassLoader(this.getClass().getClassLoader()); dataSource.setUrl(dbUrl); dataSource.setUsername(user); dataSource.setPassword(passw); dataSource.setMaxWaitMillis(maxWaitMillis); dataSource.setMaxTotal(maxTotal); dataSource.setMinIdle(minIdle); dataSource.setMaxIdle(maxIdle); dataSource.setMaxConnLifetimeMillis(maxConnLifetimeMillis); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setSoftMinEvictableIdleTimeMillis(softMinEvictableIdleTimeMillis); if (StringUtils.isEmpty(validationQuery)) { dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(true); } }
Example 20
Source File: Dbcp2DataSourcePool.java From Zebra with Apache License 2.0 | 4 votes |
@Override public DataSource build(DataSourceConfig config, boolean withDefaultValue) { BasicDataSource dbcp2DataSource = new BasicDataSource(); dbcp2DataSource.setUrl(config.getJdbcUrl()); dbcp2DataSource.setUsername(config.getUsername()); dbcp2DataSource.setPassword(config.getPassword()); dbcp2DataSource.setDriverClassName(StringUtils.isNotBlank(config.getDriverClass()) ? config.getDriverClass() : JdbcDriverClassHelper.getDriverClassNameByJdbcUrl(config.getJdbcUrl())); if (withDefaultValue) { dbcp2DataSource.setInitialSize(getIntProperty(config, "initialPoolSize", 5)); dbcp2DataSource.setMaxTotal(getIntProperty(config, "maxPoolSize", 30)); dbcp2DataSource.setMinIdle(getIntProperty(config, "minPoolSize", 5)); dbcp2DataSource.setMaxIdle(getIntProperty(config, "maxPoolSize", 20)); dbcp2DataSource.setMaxWaitMillis(getIntProperty(config, "checkoutTimeout", 1000)); dbcp2DataSource.setValidationQuery(getStringProperty(config, "preferredTestQuery", "SELECT 1")); dbcp2DataSource.setMinEvictableIdleTimeMillis(getIntProperty(config, "minEvictableIdleTimeMillis", 1800000));// 30min dbcp2DataSource .setTimeBetweenEvictionRunsMillis(getIntProperty(config, "timeBetweenEvictionRunsMillis", 30000)); // 30s dbcp2DataSource.setRemoveAbandonedTimeout(getIntProperty(config, "removeAbandonedTimeout", 300)); // 30s dbcp2DataSource.setNumTestsPerEvictionRun(getIntProperty(config, "numTestsPerEvictionRun", 6)); // 30s dbcp2DataSource.setValidationQueryTimeout(getIntProperty(config, "validationQueryTimeout", 0)); if (StringUtils.isNotBlank(getStringProperty(config, "connectionInitSql", null))) { List<String> initSqls = new ArrayList<String>(); initSqls.add(getStringProperty(config, "connectionInitSql", null)); dbcp2DataSource.setConnectionInitSqls(initSqls); } dbcp2DataSource.setTestWhileIdle(true); dbcp2DataSource.setTestOnBorrow(false); dbcp2DataSource.setTestOnReturn(false); dbcp2DataSource.setRemoveAbandonedOnBorrow(true); dbcp2DataSource.setRemoveAbandonedOnMaintenance(true); } else { try { PropertiesInit<BasicDataSource> propertiesInit = new PropertiesInit<BasicDataSource>(dbcp2DataSource); propertiesInit.initPoolProperties(config); } catch (Exception e) { throw new ZebraConfigException(String.format("dbcp2 dataSource [%s] created error : ", config.getId()), e); } } this.pool = dbcp2DataSource; LOGGER.info(String.format("New dataSource [%s] created.", config.getId())); return this.pool; }