Example usage for org.apache.commons.dbcp BasicDataSource setDriverClassName

List of usage examples for org.apache.commons.dbcp BasicDataSource setDriverClassName

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource setDriverClassName.

Prototype

public synchronized void setDriverClassName(String driverClassName) 

Source Link

Document

Sets the jdbc driver class name.

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:net.jetrix.DataSourceManager.java

/**
 * Configure a datasource./*from   ww w .j  a  va  2 s  .c o m*/
 *
 * @param config      the configuration of the datasource
 * @param environment the environment of the datasource
 */
public void setDataSource(DataSourceConfig config, String environment) {
    try {
        Class.forName(config.getDriver());
    } catch (ClassNotFoundException e) {
        log.warning("Unable to find the database driver (" + config.getDriver()
                + "), put the related jar in the lib directory");
        return;
    }

    try {
        // close the previous datasource if necessary
        if (datasources.containsKey(environment)) {
            BasicDataSource datasource = (BasicDataSource) datasources.get(environment);
            datasource.close();
        }

        BasicDataSource datasource = new BasicDataSource();
        datasource.setDefaultAutoCommit(false);

        datasource.setDriverClassName(config.getDriver());
        datasource.setUrl(config.getUrl());
        datasource.setUsername(config.getUsername());
        datasource.setPassword(config.getPassword());
        datasource.setMinIdle(config.getMinIdle() != 0 ? config.getMinIdle() : DEFAULT_MIN_IDLE);
        datasource.setMaxActive(config.getMaxActive() != 0 ? config.getMaxActive() : DEFAULT_MAX_ACTIVE);

        // attempts to open the connection
        datasource.getConnection().close();

        datasources.put(environment, datasource);
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unable to configure the datasource '" + environment + "'", e);
    }
}

From source file:com.uber.hoodie.hive.client.HoodieHiveClient.java

private DataSource getDatasource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverName);
    ds.setUrl(getHiveJdbcUrlWithDefaultDBName());
    ds.setUsername(configuration.getHiveUsername());
    ds.setPassword(configuration.getHivePassword());
    return ds;// w w  w .  jav a 2 s . c  o  m
}

From source file:com.agiletec.ConfigTestUtils.java

private void createDatasource(String dsNameControlKey, SimpleNamingContextBuilder builder,
        Properties testConfig) {// w  w w .j av  a2 s .c om
    String beanName = testConfig.getProperty("jdbc." + dsNameControlKey + ".beanName");
    try {
        String className = testConfig.getProperty("jdbc." + dsNameControlKey + ".driverClassName");
        String url = testConfig.getProperty("jdbc." + dsNameControlKey + ".url");
        String username = testConfig.getProperty("jdbc." + dsNameControlKey + ".username");
        String password = testConfig.getProperty("jdbc." + dsNameControlKey + ".password");
        Class.forName(className);
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setMaxActive(8);
        ds.setMaxIdle(4);
        ds.setDriverClassName(className);
        builder.bind("java:comp/env/jdbc/" + beanName, ds);
    } catch (Throwable t) {
        throw new RuntimeException("Error on creation datasource '" + beanName + "'", t);
    }
}

From source file:com.miserablemind.butter.bootstrap.RootContext.java

/**
 * Data Source Bean that is configured for JDBC connection using {@link ConfigJDBC}.
 *
 * @return {@link BasicDataSource} bean with a name {@code dataSource}.
 *///from  w  w w  . j  ava 2s .c  om
@Bean(name = "dataSource")
public BasicDataSource dataSource() {

    ConfigJDBC configJDBC = this.configSystem.getConfigJDBC();

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUsername(configJDBC.getJdbcUsername());
    dataSource.setPassword(configJDBC.getJdbcPassword());
    dataSource.setUrl(configJDBC.getJdbcUrl());
    dataSource.setDriverClassName(configJDBC.getJdbcDriverClassName());

    return dataSource;
}

From source file:com.atypon.wayf.guice.WayfGuiceModule.java

@Provides
@Singleton/*from   w  ww  . ja v a  2 s  . c o  m*/
public NamedParameterJdbcTemplate getJdbcTemplate(@Named("jdbc.driver") String driver,
        @Named("jdbc.username") String username, @Named("jdbc.password") String password,
        @Named("jdbc.url") String url, @Named("jdbc.maxActive") Integer maxActive,
        @Named("jdbc.maxIdle") Integer maxIdle, @Named("jdbc.initialSize") Integer initialSize,
        @Named("jdbc.validationQuery") String validationQuery) {
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(driver);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setUrl(url);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setInitialSize(initialSize);
    dataSource.setValidationQuery(validationQuery);

    return new NamedParameterJdbcTemplate(dataSource);
}

From source file:com.bstek.dorado.core.store.SqlBaseStoreSupport.java

protected synchronized DataSource getDataSource() throws Exception {
    if (dataSource != null) {
        return dataSource;
    }/*  w w w.  ja v a  2 s  .  com*/

    if (StringUtils.isBlank(namespace)) {
        throw new IllegalArgumentException("The namespace of store cannot be empty. ");
    }

    prepareNamespace();

    BasicDataSource pds = new BasicDataSource();
    dataSource = pds;

    pds.setDriverClassName(driverClassName);
    pds.setUrl(getConnectionUrl());
    pds.setUsername(username);
    pds.setPassword(password);
    pds.setDefaultCatalog(defaultCatalog);

    if (defaultAutoCommit != null) {
        pds.setDefaultAutoCommit(defaultAutoCommit.booleanValue());
    }
    if (defaultReadOnly != null) {
        pds.setDefaultReadOnly(defaultReadOnly.booleanValue());
    }
    if (defaultTransactionIsolation != null) {
        pds.setDefaultTransactionIsolation(defaultTransactionIsolation.intValue());
    }
    if (maxActive != null) {
        pds.setMaxActive(maxActive.intValue());
    }
    if (maxIdle != null) {
        pds.setMaxIdle(maxIdle.intValue());
    }
    if (minIdle != null) {
        pds.setMinIdle(minIdle.intValue());
    }
    if (initialSize != null) {
        pds.setInitialSize(initialSize.intValue());
    }
    if (maxWait != null) {
        pds.setMaxWait(maxWait.longValue());
    }
    if (timeBetweenEvictionRunsMillis != null) {
        pds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis.longValue());
    }
    if (minEvictableIdleTimeMillis != null) {
        pds.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis.longValue());
    }
    return dataSource;
}

From source file:com.alibaba.druid.benckmark.pool.Case_Concurrent_50.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);// ww w .j ava  2s .c  om
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }

    System.out.println();
}

From source file:com.manpowergroup.cn.icloud.util.Case0.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*ww w . j ava  2s . c  o m*/
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }
    System.out.println();
}

From source file:com.alibaba.druid.benckmark.pool.Oracle_Case0.java

public void test_1() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//from   w  ww. ja  va2 s .  c  om
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(true);

    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "dbcp");
    }
    System.out.println();
}

From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.dao.mysqlImpl.AbstractJDBCBaseDao.java

private synchronized BasicDataSource createConnectionPool() {
    BasicDataSource source;
    logger.debug("creating connectionpool");
    String driver = bundle.getString("dbDriver");
    String user = bundle.getString("dbUser");
    String pass = bundle.getString("dbPass");
    String url = bundle.getString("dbUrl");
    url = url + "?user=" + user + "&password=" + pass;
    source = new BasicDataSource();
    source.setDriverClassName(driver);
    source.setUsername(user);/*from  ww  w .  ja v a2 s  .  co m*/
    source.setPassword(pass);
    source.setUrl(url);
    source.setTestOnReturn(true);
    source.setValidationQuery("SELECT 1");
    logger.debug("connectionpool created");
    return source;
}