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

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

Introduction

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

Prototype

BasicDataSource

Source Link

Usage

From source file:org.qi4j.library.sql.ds.DBCPBasicDataSourceServiceMixin.java

public void activate() throws Exception {
    dataSource = new BasicDataSource();
    dataSource.setUrl(configuration.configuration().url().get());
}

From source file:org.quartz.utils.PoolingConnectionProvider.java

/**
 * Create the underlying DBCP BasicDataSource with the 
 * default supported properties.//from  w  ww  . ja v  a  2s . c  o  m
 */
private void initialize(String dbDriver, String dbURL, String dbUser, String dbPassword, int maxConnections,
        String dbValidationQuery) throws SQLException {
    if (dbURL == null) {
        throw new SQLException("DBPool could not be created: DB URL cannot be null");
    }

    if (dbDriver == null) {
        throw new SQLException(
                "DBPool '" + dbURL + "' could not be created: " + "DB driver class name cannot be null!");
    }

    if (maxConnections < 0) {
        throw new SQLException(
                "DBPool '" + dbURL + "' could not be created: " + "Max connections must be greater than zero!");
    }

    datasource = new BasicDataSource();
    datasource.setDriverClassName(dbDriver);
    datasource.setUrl(dbURL);
    datasource.setUsername(dbUser);
    datasource.setPassword(dbPassword);
    datasource.setMaxActive(maxConnections);
    if (dbValidationQuery != null) {
        datasource.setValidationQuery(dbValidationQuery);
    }
}

From source file:org.raistlic.spring.test.flyway.FlywayTestConfiguration.java

@Bean
public DataSource dataSource() {

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    dataSource.setUrl("jdbc:derby:test;create=true");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    return dataSource;
}

From source file:org.runway.utils.ServerBean.java

public static void main(String[] args) {

    //String propFileName = args[0];
    Properties props = new Properties();

    props.put("server.port", "9101");
    props.put("server.database.0", "emarket.db");
    props.put("server.dbname.0", "shark");

    BasicDataSource datasource = new BasicDataSource();

    datasource.setDriverClassName("org.hsqldb.jdbcDriver");
    datasource.setUrl("jdbc:hsqldb:hsql://localhost:9101/shark");
    datasource.setUsername("sa");
    datasource.setPassword("");

    ServerBean server = new ServerBean();

    server.setServerProperties(props);/*from   w w w  .  j  av a2  s .c  o m*/
    server.setDataSource(datasource);

    try {
        server.initialize();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.sbq.batch.configurations.DatabaseConfiguration.java

@Bean(destroyMethod = "close")
public DataSource dbcpDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/batch_db");
    dataSource.setUsername("root");
    dataSource.setPassword("");
    dataSource.setMaxActive(20);/*from www.  j  a va  2  s .  c  om*/
    dataSource.setMaxIdle(20);
    dataSource.setMaxWait(10000);
    dataSource.setInitialSize(5);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    return dataSource;
}

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);//  www. j a  v  a2s . c  om
    basicDataSource.setUsername(user);
    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);/*from ww w  .  j  a va 2s  . c  om*/
    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 .j  a  va 2 s  .c  om*/
    }

}

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

/**
 * Create datasource by dbsettign// w w  w  .  ja va2  s.  co m
 * ?????
 * @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;
}