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:xbird.util.jdbc.datasource.DbcpDataSourceProvider.java

public DataSource setupDataSource(String connectURI) {
    // creates DataSource
    BasicDataSource ds = new BasicDataSource();

    // for debugging.
    if (Settings.isLoggingEnabled) {
        ds.setAccessToUnderlyingConnectionAllowed(true);
    }/*from   w  w w  .j ava2  s .  c  om*/

    ds.setDriverClassName(DriverClassNameResolver.resolve(Settings.get("xbird.db.kind")));

    // sets up DataSource
    ds.setUrl(connectURI);
    final String dbuser = Settings.get("xbird.db.user");
    final String dbpasswd = Settings.get("xbird.db.passwd");
    if (dbuser != null && dbuser.length() != 0) {
        ds.setUsername(dbuser);
        ds.setPassword(dbpasswd);
    }

    // addtinal settings.
    final String maxactive = Settings.get("xbird.db.pool.maxactive");
    if (maxactive != null)
        ds.setMaxActive(Integer.parseInt(maxactive));

    final String maxidle = Settings.get("xbird.db.pool.maxidle");
    if (maxidle != null)
        ds.setMaxIdle(Integer.parseInt(maxidle));

    final String maxwait = Settings.get("xbird.db.pool.maxwait");
    ds.setMaxWait(maxwait == null ? DEFAULT_MAXWAIT : Integer.parseInt(maxwait));

    ds.setDefaultAutoCommit(true);
    //ds.setDefaultReadOnly(false);

    final String initialsize = Settings.get("xbird.db.pool.initialsize");
    ds.setInitialSize(initialsize == null ? DEFAULT_INITIAL_POLLSIZE : Integer.parseInt(initialsize));

    // sets up for PreparedStatements.
    ds.setPoolPreparedStatements(true);

    final String maxOpenPreparedStatements = Settings.get("xbird.db.pool.statement.cache_size");
    ds.setMaxOpenPreparedStatements(maxOpenPreparedStatements == null ? MAX_OPEN_PREPARED_STATEMENTS
            : Integer.parseInt(maxOpenPreparedStatements));

    return ds;
}

From source file:za.co.dwarfsun.jcmanager.app.conf.ConnectionConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/JobCardDB");
    ds.setUsername("jobcard");
    ds.setPassword("jobcard");
    return ds;//from w w w.j a va 2s  .  c  om
}

From source file:za.co.dwarfsun.jobcardmanager.test.ConnectionConfigTest.java

@Bean
public DataSource dataSource() {
    BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource();
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUrl("jdbc:derby://localhost:1527/JobCardDB");
    ds.setUsername("jobcard");
    ds.setPassword("jobcard");
    return ds;/*  www  . ja va  2 s .  com*/
}