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:cn.com.sims.crawler.util.JDBCHelper.java

public static JdbcTemplate createMysqlTemplate(String templateName, String url, String username,
        String password, int initialSize, int maxActive) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(url);
    dataSource.setUsername(username);//from  w  w  w. j a va2 s .c  om
    dataSource.setPassword(password);
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    JdbcTemplate template = new JdbcTemplate(dataSource);
    templateMap.put(templateName, template);
    return template;
}

From source file:com.weibo.datasys.parser.sql.DBConnectionFactory.java

public static void init() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(ConfigFactory.getString("jdbc.driverClassName"));
    dataSource.setUrl(ConfigFactory.getString("jdbc.url"));
    dataSource.setUsername(ConfigFactory.getString("jdbc.username"));
    dataSource.setPassword(ConfigFactory.getString("jdbc.password"));

    dataSource.setInitialSize(ConfigFactory.getInt("jdbc.initialSize", 1));
    dataSource.setMinIdle(ConfigFactory.getInt("jdbc.minIdle", 2));
    dataSource.setMaxIdle(ConfigFactory.getInt("jdbc.maxIdle", 10));
    dataSource.setMaxWait(ConfigFactory.getInt("jdbc.maxWait", 1000));
    dataSource.setMaxActive(ConfigFactory.getInt("jdbc.maxActive", 2));
    dataSource.addConnectionProperty("autoReconnect", "true");
    // ??//from w w w.j a  v  a  2  s.com
    dataSource.setTestWhileIdle(true);
    // ?sql?
    dataSource.setValidationQuery("select 'test'");
    // ?
    dataSource.setValidationQueryTimeout(5000);
    // 
    dataSource.setTimeBetweenEvictionRunsMillis(3600000);
    // ??
    dataSource.setMinEvictableIdleTimeMillis(3600000);

    ds = dataSource;
}

From source file:com.dangdang.ddframe.rdb.sharding.config.yaml.AbstractYamlShardingDataSourceTest.java

protected static DataSource createDataSource(final String dsName) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(org.h2.Driver.class.getName());
    result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL", dsName));
    result.setUsername("sa");
    result.setPassword("");
    result.setMaxActive(100);/*  w ww. j  a v a 2 s.  c o  m*/
    return result;
}

From source file:com.flytxt.commons.reporting.connection.ConnectionProvider.java

private static DataSource getDs() {
    if (ds == null) {
        BasicDataSource bds = new BasicDataSource();
        bds.setDriverClassName(DbConnectionPropertiesProvider.getDriver());
        bds.setUrl(DbConnectionPropertiesProvider.getUrl());
        bds.setUsername(DbConnectionPropertiesProvider.getUser());
        bds.setPassword(DbConnectionPropertiesProvider.getPwd());

        // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Active : "+bds.getNumActive());
        // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Idle : "+bds.getNumIdle());

        ds = bds;/*from w w w  . j av  a2s .  co m*/

    }

    return ds;
}

From source file:com.dangdang.ddframe.job.example.JavaLiteJobMain.java

private static DataSource setUpEventTraceDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(EVENT_RDB_STORAGE_DRIVER);
    result.setUrl(EVENT_RDB_STORAGE_URL);
    result.setUsername(EVENT_RDB_STORAGE_USERNAME);
    result.setPassword(EVENT_RDB_STORAGE_PASSWORD);
    return result;
}

From source file:com.cgdecker.guice.jdbc.Hsqldb.java

public static DataSource getDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(jdbcDriver.class.getName());
    result.setUrl("jdbc:hsqldb:mem:.");
    result.setUsername("sa");
    result.setPassword("");
    setUpDatabase(result);//from  w w w .  jav  a2s. c  om
    return result;
}

From source file:com.dangdang.ddframe.rdb.sharding.example.jdbc.Main.java

private static DataSource createDataSource(final String dataSourceName) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
    result.setUrl(String.format("jdbc:mysql://localhost:3306/%s", dataSourceName));
    result.setUsername("root");
    result.setPassword("");
    return result;
}

From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java

public static synchronized LookupDataSource getDataSource() throws CacheRefreshException {
    if (dataSource == null) {
        try {/* w  ww  .ja va 2  s.  co m*/
            Properties config = new Properties();
            config.load(new FileInputStream("lookup-connection.properties"));

            BasicDataSource ds = new BasicDataSource();
            ds.setDriverClassName(config.getProperty("lookup.class"));
            ds.setUrl(config.getProperty("lookup.url"));
            ds.setUsername(config.getProperty("lookup.username"));
            ds.setPassword(config.getProperty("lookup.password"));
            ds.setDefaultReadOnly(false);

            dataSource = new JdbcLookupDataSource(ds);
        } catch (FileNotFoundException e) {
            throw new CacheRefreshException("Could not find lookup-connection.properties file", e);
        } catch (IOException e) {
            throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file",
                    e);
        } catch (RuntimeException e) {
            throw new CacheRefreshException("Could not create data source", e);
        }
    }

    return dataSource;
}

From source file:com.uber.hoodie.cli.utils.HiveUtil.java

private static DataSource getDatasource(String jdbcUrl, String user, String pass) {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverName);//www  .j  a va2  s  . c o  m
    ds.setUrl(jdbcUrl);
    ds.setUsername(user);
    ds.setPassword(pass);
    return ds;
}

From source file:com.dangdang.ddframe.rdb.sharding.example.transaction.Main.java

private static DataSource createTransactionLogDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
    result.setUrl("jdbc:mysql://localhost:3306/trans_log");
    result.setUsername("root");
    result.setPassword("");
    return result;
}