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

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

Introduction

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

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

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

Usage

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);//from   w  ww  . ja  v a 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.manpowergroup.cn.icloud.util.Case0.java

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//from w  ww  . j  a va 2s .  co 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 w w  .ja  va2s  .  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:fr.cnes.sitools.datasource.jdbc.business.SitoolsSQLDataSourceFactory.java

/**
 * Local creation of a DataSource/*from   w  w w .  j a v  a  2s. c om*/
 * 
 * @param driver
 *          the database driver
 * @param connectURI
 *          the URI to connect
 * @param userName
 *          the database user name
 * @param password
 *          the password
 * @param schemaOnConnection
 *          the schema on connection
 * @return SitoolsDataSource a standard data source for SITools
 */
public SitoolsSQLDataSource setupDataSource(String driver, String connectURI, String userName, String password,
        String schemaOnConnection) {

    String key = connectURI + "@" + userName;
    SitoolsSQLDataSource foundDatasource = dataSources.get(key);
    if (foundDatasource == null) {

        BasicDataSource ds = new BasicDataSource();
        // OSGi
        ds.setDriverClassLoader(getClass().getClassLoader());
        ds.setDriverClassName(driver);
        ds.setUsername(userName);
        ds.setPassword(password);
        ds.setUrl(connectURI);
        ds.setMaxActive(10);
        ds.setInitialSize(1);
        // test that the connection is alive on each request. If not It will be dropped from the pool and another
        // connection will be created
        if (!"org.hsqldb.jdbcDriver".equals(driver)) {
            ds.setTestOnBorrow(true);
            ds.setValidationQuery("SELECT 1");
        }
        // ds.setDefaultReadOnly(false);
        // ds.setDefaultAutoCommit(true);
        JDBCDataSource jdbcDS = new JDBCDataSource();
        jdbcDS.setName(key);
        jdbcDS.setDriverClass(driver);
        foundDatasource = new SitoolsSQLDataSource(jdbcDS, ds, schemaOnConnection);
        dataSources.put(key, foundDatasource);
    }
    return foundDatasource;
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//from  w  w  w  . j a v a 2 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("SELECT 1");
    dataSource.setTestOnBorrow(false);

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

From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java

private DataSource getDbDataSource() {
    String url = null;/* w  w w  .  java  2s.c  o m*/
    String username = null;
    String password = null;
    if (ebaoProp.containsKey("url")) {
        url = ebaoProp.getProperty("url");
    }
    if (ebaoProp.containsKey("username")) {
        username = ebaoProp.getProperty("username");
    }
    if (ebaoProp.containsKey("password")) {
        password = ebaoProp.getProperty("password");
    }
    BasicDataSource bds = new BasicDataSource();
    bds.setUrl(url);
    bds.setUsername(username);
    bds.setPassword(password);
    bds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    return bds;
}

From source file:fr.cnes.sitools.datasource.jdbc.business.SitoolsDataSourceFactory.java

/**
 * Setup a dataSource for "users". Usage is for all users for consultation functions.
 * /*from w  w w. j  a  v  a 2s .c om*/
 * @param dataSource
 *          the DataSource to update
 * @return SitoolsDataSource the new DataSource
 */
public SitoolsDataSource setupDataSourceForUsers(JDBCDataSource dataSource) {
    String key = dataSource.getId();
    SitoolsDataSource foundDatasource = dataSources.get(key);
    if (foundDatasource == null) {

        BasicDataSource ds = new BasicDataSource();
        // OSGi
        ds.setDriverClassLoader(getClass().getClassLoader());
        ds.setDriverClassName(dataSource.getDriverClass());
        ds.setUsername(dataSource.getUserLogin());
        ds.setPassword(dataSource.getUserPassword());
        ds.setUrl(dataSource.getUrl());
        ds.setMaxActive(dataSource.getMaxActive());
        ds.setInitialSize(dataSource.getInitialSize());
        ds.setDefaultReadOnly(true);
        if ((dataSource.getSchemaOnConnection() != null) && !dataSource.getSchemaOnConnection().equals("")) {
            ds.setDefaultCatalog(dataSource.getSchemaOnConnection());
        }
        foundDatasource = new SitoolsDataSource(dataSource, ds, dataSource.getSchemaOnConnection());
        dataSources.put(key, foundDatasource);
    }
    return foundDatasource;
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from www  .  j  ava 2 s .co  m*/
    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("SELECT 1");
    dataSource.setTestOnBorrow(testOnBorrow);

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

From source file:cn.vlabs.umt.common.datasource.DatabaseUtil.java

public DatabaseUtil(Config config) {
    BasicDataSource ds = new BasicDataSource();

    ds.setMaxActive(config.getInt("database.maxconn", 10));
    ds.setMaxIdle(config.getInt("database.maxidle", 3));
    ds.setMaxWait(100);/*  w w w.  java  2  s . co  m*/

    ds.setUsername(config.getStringProp("database.username", null));
    ds.setPassword(config.getStringProp("database.password", null));
    ds.setDriverClassName(config.getStringProp("database.driver", null));
    ds.setUrl(config.getStringProp("database.conn-url", null));
    ds.setTimeBetweenEvictionRunsMillis(3600000);
    ds.setMinEvictableIdleTimeMillis(1200000);
    datasource = ds;
}

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

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

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//from  w  w  w  .  ja va  2  s.  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();
}