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:com.dangdang.ddframe.rdb.integrate.AbstractDBUnitTest.java

private DataSource createDataSource(final String dataSetFile) {
    if (DATA_SOURCES.containsKey(dataSetFile)) {
        return DATA_SOURCES.get(dataSetFile);
    }// ww  w. ja  v  a2s  .  com
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(dbEnv.getDriverClassName());
    result.setUrl(dbEnv.getURL(getFileName(dataSetFile)));
    result.setUsername(dbEnv.getUsername());
    result.setPassword(dbEnv.getPassword());
    result.setMaxActive(1000);
    DATA_SOURCES.put(dataSetFile, result);
    return result;
}

From source file:com.consol.citrus.samples.todolist.dao.JdbcTodoListDao.java

private DataSource createDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:hsql://localhost/testdb");
    dataSource.setUsername("sa");
    dataSource.setPassword("");

    return dataSource;
}

From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbStorageTest.java

@Before
public void setup() throws SQLException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(org.h2.Driver.class.getName());
    dataSource.setUrl("jdbc:h2:mem:job_event_storage");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    storage = new JobEventRdbStorage(dataSource);
}

From source file:com.musala.testutils.DatabaseTestConfiguration.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName")));
    dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url")));
    return dataSource;
}

From source file:com.bt.aloha.testing.JdbcHelper.java

private DataSource buildDataSource(String driver, String url, String username, String password)
        throws Exception {
    log.debug(String.format("Building datasource %s, %s, %s, %s", driver, url, username, password));
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName(driver);
    ds.setUrl(url);// w  w  w.  j  a va  2  s. co  m
    ds.setUsername(username);
    ds.setPassword(password);

    return ds;
}

From source file:com.otterca.persistence.dao.H2Configuration.java

/**
 * Get dataSource for H2 database./*from  w  ww. jav a  2 s.com*/
 * 
 * @return
 */
@Bean
public DataSource getDataSource() {
    if (dataSource == null) {
        synchronized (this) {
            if (dataSource == null) {
                BasicDataSource ds = new BasicDataSource();
                ds.setDriverClassName(bundle.getString("driverClassName"));
                ds.setUrl(bundle.getString("url"));
                ds.setUsername(bundle.getString("username"));
                BasicTextEncryptor encryptor = new BasicTextEncryptor();
                encryptor.setPassword(masterkey.getString("master.password"));
                ds.setPassword(encryptor.decrypt(bundle.getString("password")));
                ds.setValidationQuery(bundle.getString("validationQuery"));
                dataSource = ds;
            }
        }
    }
    return dataSource;
}

From source file:fr.gouv.diplomatie.applitutoriel.integration.conf.DataSourceConf.java

@Bean
public DataSource dataSource() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(url);/*from  w  w w.  ja  v  a2 s .  c o m*/
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestWhileIdle(testWhileIdle);
    dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    dataSource.setRemoveAbandoned(removeAbandoned);
    dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
    dataSource.setLogAbandoned(logAbandoned);
    return dataSource;
}

From source file:herddb.jdbc.CommonsDBCPTest.java

@Test
public void test() throws Exception {
    try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
        server.start();//from   ww  w. j a  va2 s. c  o m
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:herddb:server:localhost:7000?");
        dataSource.setDriverClassName(Driver.class.getName());
        try (Connection connection = dataSource.getConnection();
                Statement statement = connection.createStatement();
                ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            int count = 0;
            while (rs.next()) {
                System.out.println("table: " + rs.getString(1));
                count++;
            }
            assertTrue(count > 0);
        }
        dataSource.close();

    }
}

From source file:$.DataSourceConf.java

@Bean
    public DataSource dataSource() {
        final BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);//w w w .  ja  va2  s. c om
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setValidationQuery(validationQuery);
        dataSource.setMaxActive(maxActive);
        dataSource.setMaxIdle(maxIdle);
        dataSource.setMaxWait(maxWait);
        dataSource.setTestOnBorrow(testOnBorrow);
        dataSource.setTestWhileIdle(testWhileIdle);
        dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
        dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
        dataSource.setRemoveAbandoned(removeAbandoned);
        dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout);
        dataSource.setLogAbandoned(logAbandoned);
        return dataSource;
    }

From source file:io.springagora.store.ApplicationConfig.java

/**
 * Bean definition.//from   w  w  w  .  j  a v a 2  s.co m
 * 
 * Datasource used to retrieve connections for the persistence layer. It's
 * configured following definitions written in {@code application.properties}.
 * 
 * @return
 *      The {@code Datasource} object, that will act as the connection pool,
 *      providing connections to the application. 
 * 
 * @throws SQLException
 *      If any error occurs during the connection attempt, it will be thrown
 *      as a {@code SQLException}.
 */
@Bean
public DataSource dataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl(connectionUrl);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setInitialSize(5);
    ds.setMaxActive(20);
    ds.setDefaultAutoCommit(false);
    return ds;
}