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

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

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 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.javacreed.secureproperties.utils.DbHelper.java

/**
 *
 * @return//from  www  .j a v a2  s  .  c  o m
 * @throws SQLException
 */
public static DbHelper create() throws SQLException {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUrl("jdbc:h2:./target/test");
    dataSource.setUsername("sa");
    dataSource.setPassword("");

    final DbHelper helper = new DbHelper(dataSource);
    return helper;
}

From source file:com.rhino.data.db.DataSourceFactory.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }/* ww w  .  ja  v  a  2s .c o  m*/
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:com.fluke.database.DatabaseProperty.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }//from  w w  w.  ja  v a2 s  . c  o  m
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("config/mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:edu.emory.cci.aiw.i2b2etl.ConfigurationFactory.java

private static BasicDataSource newBasicDataSource(String url) {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(DRIVER_CLASS_NAME);
    bds.setUrl(url);/*w  w w.  j  a  v  a2 s.  c o  m*/
    bds.setMinIdle(MIN_IDLE);
    bds.setMaxIdle(MAX_IDLE);
    bds.setMaxTotal(MAX_TOTAL);
    return bds;
}

From source file:dgw.mt940.db.util.DGWBasicDataSource.java

public static DataSource setupDataSource(String connectURI, String driver, String userName, String password,
        String removeAbandoned, String initSize, String mxSize) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUrl(connectURI);//from w ww  . jav a  2 s .  co m
    ds.setUsername(userName);
    ds.setPassword(password);
    ds.setUrl(connectURI);
    ds.setAbandonedUsageTracking(Boolean.getBoolean(removeAbandoned));
    ds.setInitialSize(Integer.parseInt(initSize));
    ds.setMaxIdle(Integer.parseInt(mxSize));
    return ds;
}

From source file:br.com.ceosites.cachedproperties.cache.test.util.DatabaseUtils.java

public static DataSource prepareDatabase() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:dataSource?hsqldb.sqllog=3");
    dataSource.setUsername("SA");
    dataSource.setPassword("");
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    ScriptRunner scriptRunner = new ScriptRunner(dataSource);

    try {//from ww w.jav a2 s . c o  m
        scriptRunner.execute(new BufferedReader(new FileReader("src/main/resources/db/create-db.sql")));
        scriptRunner.execute(new BufferedReader(new FileReader("src/main/resources/db/insert-data.sql")));
    } catch (IOException ex) {
        LOGGER.error("Error on read SQL files.", ex);
    } catch (SQLException ex) {
        LOGGER.error("Error on  execute SQL script.", ex);
    }

    return dataSource;
}

From source file:common.DBHelper.java

public static DataSource getDataSource() {

    Properties prop = new Properties();

    try (InputStream input = DBHelper.class.getResourceAsStream("/config.PROPERTIES");) {
        prop.load(input);/*ww w. ja  va2s.  c om*/
    } catch (IOException e) {
        logger.error("error reading properties", e);
    }

    BasicDataSource ds = new BasicDataSource();

    ds.setUrl(prop.getProperty("dbUrl"));
    ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    ds.setUsername(prop.getProperty("dbUsername"));
    ds.setPassword(prop.getProperty("dbPassword"));

    return ds;
}

From source file:de.anycook.db.mysql.DBHandler.java

private static BasicDataSource setupDataSource(String server, int port, String dbName, String username,
        String password, int maxActive, int maxIdle) {
    Preconditions.checkNotNull(server);/*from  w w  w .  ja  v a  2s .c  o  m*/
    Preconditions.checkNotNull(dbName);
    Preconditions.checkNotNull(username);

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUsername(username);

    if (password.length() > 0) {
        ds.setPassword(password);
    }

    String url = String.format("jdbc:mysql://%s:%d/%s?useConfigs=maxPerformance&useCompression=true", server,
            port, dbName);
    ds.setUrl(url);
    ds.setValidationQuery("SELECT 1;");
    ds.setTestWhileIdle(true);
    ds.setTestOnReturn(true);
    ds.setMaxTotal(maxActive);
    ds.setMaxIdle(maxIdle);
    ds.setRemoveAbandonedOnBorrow(true);
    ds.setRemoveAbandonedTimeout(60);

    if (Configuration.getInstance().isDeveloperMode()) {
        ds.setLogAbandoned(true);
    }

    sLogger.info("created new Connectionpool");
    return ds;
}

From source file:com.bc.fiduceo.TestUtil.java

public static BasicDataSource getdatasourceMongoDb() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("mongodb");
    dataSource.setUrl("mongodb://localhost:27017");
    dataSource.setUsername("fiduceo");
    dataSource.setPassword("oecudif");
    return dataSource;
}

From source file:com.bc.fiduceo.TestUtil.java

public static BasicDataSource getDatasource_H2() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    // the following line dumps all database interactions to the console window tb 2016-02-10
    //        dataSource.setUrl("jdbc:h2:mem:fiduceo;TRACE_LEVEL_SYSTEM_OUT=2");
    dataSource.setUrl("jdbc:h2:mem:fiduceo");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    return dataSource;
}