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:org.seedstack.seed.persistence.jdbc.internal.datasource.DbcpDataSourceProvider.java

@Override
public DataSource provide(String driverClass, String url, String user, String password,
        Properties dataSourceProperties) {
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(driverClass);
    basicDataSource.setUrl(url);
    basicDataSource.setUsername(user);//from   ww w  .j ava  2 s .co  m
    basicDataSource.setPassword(password);
    for (Object key : dataSourceProperties.keySet()) {
        basicDataSource.addConnectionProperty((String) key, dataSourceProperties.getProperty((String) key));
    }
    return basicDataSource;
}

From source file:org.shelloid.vpt.rms.util.Platform.java

private BasicDataSource configDbPool() {
    BasicDataSource ds = new BasicDataSource();
    ds.setTestOnBorrow(true);//w w w. j  a va 2  s.  co m
    ds.setValidationQuery("SELECT 1");
    ds.setDriverClassName(get(Configurations.ConfigParams.JDBC_DRIVER));
    ds.setUrl(get(Configurations.ConfigParams.JDBC_URL));
    ds.setUsername(get(Configurations.ConfigParams.JDBC_USERNAME));
    ds.setPassword(get(Configurations.ConfigParams.JDBC_PASSWORD));
    ds.setMaxActive(Integer.parseInt(get(Configurations.ConfigParams.JDBC_MAX_ACTIVE)));
    ds.setMaxIdle(Integer.parseInt(get(Configurations.ConfigParams.JDBC_MIN_IDLE)));
    return ds;
}

From source file:org.smart.migrate.setting.DataSourceTest.java

@Test
public void testDataSource() {
    DBSetting dbs = new DBSetting(DBType.MySQL, "localhost", "3306", "smartData", "root", null);
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(dbs.getdBType().getDriver());
    dataSource.setUrl(dbs.getConnectUrl());
    dataSource.setUsername(dbs.getUsername());
    dataSource.setPassword(dbs.getPassword());
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    List<Map<String, Object>> dataList = jdbcTemplate.queryForList("select * from gen_fawen");
    for (Map<String, Object> map : dataList) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();
            System.out.println(string + "," + object);
        }//from  w w  w. ja va2 s.  c  o m
    }

}

From source file:org.smart.migrate.util.ConnectionUtils.java

/**
 * Create datasource by dbsettign/*from  w  ww .j a  v  a 2 s.  com*/
 * ?????
 * @param dBSetting
 * @return
 */
public static DataSource createDataSource(DBSetting dBSetting) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(dBSetting.getdBType().getDriver());
    dataSource.setUrl(dBSetting.getConnectUrl());
    dataSource.setUsername(dBSetting.getUsername());
    dataSource.setPassword(dBSetting.getPassword());
    return dataSource;
}

From source file:org.snaker.engine.access.jdbc.JdbcHelper.java

/**
 * dataSourcedbcp??/*from  w w w. j ava2 s .  c  o m*/
 */
private static void initialize() {
    String driver = ConfigHelper.getProperty("jdbc.driver");
    String url = ConfigHelper.getProperty("jdbc.url");
    String username = ConfigHelper.getProperty("jdbc.username");
    String password = ConfigHelper.getProperty("jdbc.password");
    int maxActive = ConfigHelper.getNumerProperty("jdbc.max.active");
    int maxIdle = ConfigHelper.getNumerProperty("jdbc.max.idle");
    AssertHelper.notNull(driver);
    AssertHelper.notNull(url);
    AssertHelper.notNull(username);
    AssertHelper.notNull(password);
    //?DBCP??
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUrl(url);
    ds.setUsername(username);
    ds.setPassword(password);
    if (maxActive != 0) {
        ds.setMaxActive(maxActive);
    }
    if (maxIdle != 0) {
        ds.setMaxIdle(maxIdle);
    }
    dataSource = ds;
}

From source file:org.sonar.core.persistence.DbTemplate.java

public BasicDataSource dataSource(String driver, String user, String password, String url) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUsername(user);/*from w w  w.j a  v a  2 s.  c om*/
    dataSource.setPassword(password);
    dataSource.setUrl(url);
    return dataSource;
}

From source file:org.spc.ofp.observer.config.ObserverDataSourceConfig.java

@Primary
@Bean(destroyMethod = "close", name = { "jdbcDataSource" })
public DataSource jdbcDataSource() {
    final BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(DRIVER_CLASS);
    bds.setUrl(OBSERVER_URL);
    return bds;// w w w.  j ava 2 s .  c  o  m
}

From source file:org.springframework.batch.sample.config.DataSourceConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(environment.getProperty("batch.jdbc.driver"));
    dataSource.setUrl(environment.getProperty("batch.jdbc.url"));
    dataSource.setUsername(environment.getProperty("batch.jdbc.user"));
    dataSource.setPassword(environment.getProperty("batch.jdbc.password"));
    return dataSource;
}

From source file:org.springframework.batch.support.DatabaseTypeTestUtils.java

public static DataSource getDataSource(Class<?> driver, String url, String username, String password)
        throws Exception {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver.getName());
    dataSource.setUrl(url);
    dataSource.setUsername(username);//w w  w . j av  a2 s  .  c  om
    dataSource.setPassword(password);
    return dataSource;
}

From source file:org.springframework.samples.petclinic.config.DbcpDataSourceFactory.java

private BasicDataSource createDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(this.driverClassName);
    dataSource.setUrl(this.url);
    dataSource.setUsername(this.username);
    dataSource.setPassword(this.password);
    return dataSource;
}