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:org.geowebcache.diskquota.jdbc.JDBCQuotaStoreFactory.java

/**
 * Prepares a simple data source for the embedded H2
 * //  w w w.  j  a  v a 2 s. c om
 * @param cacheDirFinder
 * @return
 * @throws ConfigurationException
 */
private DataSource getH2DataSource(DefaultStorageFinder cacheDirFinder) throws ConfigurationException {
    File storeDirectory = new File(cacheDirFinder.getDefaultPath(), "diskquota_page_store_h2");
    storeDirectory.mkdirs();

    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName("org.h2.Driver");
    String database = new File(storeDirectory, "diskquota").getAbsolutePath();
    dataSource.setUrl("jdbc:h2:" + database);
    dataSource.setUsername("sa");
    dataSource.setPoolPreparedStatements(true);
    dataSource.setAccessToUnderlyingConnectionAllowed(true);
    dataSource.setMinIdle(1);
    dataSource.setMaxActive(-1); // boundless
    dataSource.setMaxWait(5000);
    return dataSource;
}

From source file:org.glowroot.agent.plugin.jdbc.Connections.java

static BasicDataSource createCommonsDbcpWrappedDataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    ds.setUrl("jdbc:hsqldb:mem:test");
    return ds;// w  w  w . jav a 2  s.co  m
}

From source file:org.glowroot.agent.plugin.jdbc.Connections.java

static org.apache.commons.dbcp2.BasicDataSource createCommonsDbcp2DataSource() {
    org.apache.commons.dbcp2.BasicDataSource ds = new org.apache.commons.dbcp2.BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    ds.setUrl("jdbc:hsqldb:mem:test");
    return ds;//ww w  .  j ava  2 s . c  o  m
}

From source file:org.glowroot.plugin.jdbc.Connections.java

private static Connection createCommonsDbcpWrappedConnection() throws SQLException {
    // set up database
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    ds.setUrl("jdbc:hsqldb:mem:test");
    Connection connection = ds.getConnection();
    insertRecords(connection);/*  ww w.  j ava2s.c o  m*/
    return connection;
}

From source file:org.gogoego.util.db.DBSessionFactory.java

public void connectPool(String name, String url, String driverClass, String username, String password) {

    final BasicDataSource ds = new BasicDataSource() {
        /**//from ww  w. j  ava 2 s . c om
         * DBCP 1.4's implementation is ... unexpected.  You can set a custom
         * classloader, but in fact it won't be used to load the driver.
         * Bug reported on dev@commons list.
         */
        @Override
        protected ConnectionFactory createConnectionFactory() throws SQLException {
            try {
                Driver driver = loadDriver();

                String user = username;
                if (user != null)
                    connectionProperties.put("user", user);

                String pwd = password;
                if (pwd != null)
                    connectionProperties.put("password", pwd);

                ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, url,
                        connectionProperties);
                return driverConnectionFactory;
            } catch (Exception ex) {
                throw new SQLException(ex);
            }
        }
    };

    ds.setDriverClassName(driverClass);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setUrl(url);
    DBSessionFactory.registerDataSource(name, ds);
}

From source file:org.gvsig.fmap.dal.store.jdbc.JDBCResource.java

protected DataSource createDataSource() {
    JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*/*from  ww  w  .  j a  va 2s .  c  om*/
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.gvsig.fmap.dal.store.jdbc.JDBCResource.java

protected void connectToDB() throws DataException {
    if (this.dataSource != null) {
        return;//from   w  w  w.  j  ava2s .  c  o  m
    }
    JDBCResourceParameters jdbcParams = (JDBCResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
    .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
    */

    this.dataSource = dataSource;
}

From source file:org.gvsig.fmap.dal.store.mysql.MySQLResource.java

protected DataSource createDataSource() {
    MySQLResourceParameters jdbcParams = (MySQLResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*//from www . j  av  a  2s. com
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.gvsig.fmap.dal.store.postgresql.PostgreSQLResource.java

protected DataSource createDataSource() {
    PostgreSQLResourceParameters jdbcParams = (PostgreSQLResourceParameters) this.getParameters();
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(jdbcParams.getJDBCDriverClassName());
    dataSource.setUsername(jdbcParams.getUser());
    dataSource.setPassword(jdbcParams.getPassword());
    dataSource.setUrl(jdbcParams.getUrl());

    dataSource.setMaxWait(60L * 1000); // FIXME

    // FIXME Set Pool parameters:
    /*/*from   ww w  . j a  v  a 2  s  . com*/
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxActive);
    dataSource.setMaxOpenPreparedStatements(maxActive);
    dataSource.setMaxWait(maxActive);
    dataSource.setInitialSize(initialSize);
    dataSource.setDefaultReadOnly(defaultReadOnly);
    dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    dataSource.setMinIdle(minIdle);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setTestOnReturn(testOnReturn);
    dataSource.setTestWhileIdle(testOnReturn);
    dataSource
       .setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
            
    dataSource.setAccessToUnderlyingConnectionAllowed(allow);
    dataSource.setLoginTimeout(seconds);
    dataSource.setLogWriter(out);
     */
    return dataSource;
}

From source file:org.hibernate.spatial.testing.DataSourceUtils.java

private void createBasicDataSource() {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(jdbcDriver);
    bds.setUrl(jdbcUrl);//ww  w.  j a v a  2 s.co  m
    bds.setUsername(jdbcUser);
    bds.setPassword(jdbcPass);
    dataSource = bds;
}