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

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

Introduction

In this page you can find the example usage for org.apache.commons.dbcp 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:org.polymap.catalog.h2.data.H2DataStoreFactory.java

protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException {
    String database = (String) DATABASE.lookUp(params);
    String host = (String) HOST.lookUp(params);
    BasicDataSource dataSource = new BasicDataSource();

    if (host != null && !host.equals("")) {
        Integer port = (Integer) PORT.lookUp(params);
        if (port != null && !port.equals("")) {
            dataSource.setUrl("jdbc:h2:tcp://" + host + ":" + port + "/" + database);
        } else {//w  w w. j  a  va2  s.  c o m
            dataSource.setUrl("jdbc:h2:tcp://" + host + "/" + database);
        }
    } else if (baseDirectory == null) {
        //use current working directory
        dataSource.setUrl("jdbc:h2:" + database);
    } else {
        //use directory specified if the patch is relative
        String location;
        if (!new File(database).isAbsolute()) {
            location = new File(baseDirectory, database).getAbsolutePath();
        } else {
            location = database;
        }

        // falko: add support for NIO
        String osName = System.getProperty("os.name");
        Boolean nio = (Boolean) NIO.lookUp(params);
        Boolean nioMapped = (Boolean) NIO_MAPPED.lookUp(params);

        String url = null;
        if ((nio != null && nio.booleanValue())
        /*|| osName.toLowerCase().contains( "linux" )*/) {
            url = "jdbc:h2:nio:" + location;
        } else if ((nioMapped != null && nioMapped.booleanValue())) {
            url = "jdbc:h2:nioMapped:" + location;
        } else {
            url = "jdbc:h2:file:" + location;
        }

        // falko: multi threaded on 
        //url += ";MULTI_THREADED=1";
        dataSource.setUrl(url);
    }

    String username = (String) USER.lookUp(params);
    if (username != null) {
        dataSource.setUsername(username);
    }
    String password = (String) PASSWD.lookUp(params);
    if (password != null) {
        dataSource.setPassword(password);
    }

    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setPoolPreparedStatements(false);

    return dataSource;
}

From source file:org.projectforge.continuousdb.demo.DemoMain.java

private DemoMain() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUsername("sa");
    // dataSource.setPassword("password");
    dataSource.setUrl("jdbc:hsqldb:testdatabase");

    configuration = new UpdaterConfiguration().setDialect(DatabaseDialect.HSQL).setDataSource(dataSource);
    databaseUpdateDao = configuration.getDatabaseUpdateDao();
    // TableAttribute.register(new TableAttributeHookImpl());

    // final SortedSet<UpdateEntry> updateEntries = new TreeSet<UpdateEntry>();
    // updateEntries.addAll(DatabaseCoreUpdates.getUpdateEntries(this));
    // getSystemUpdater().setUpdateEntries(updateEntries);
}

From source file:org.projectforge.continuousdb.demo.UpdateEntryDemoMain.java

private UpdateEntryDemoMain() {
    final BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUsername("sa");
    // dataSource.setPassword("password");
    dataSource.setUrl("jdbc:hsqldb:testdatabase");

    configuration = new UpdaterConfiguration().setDialect(DatabaseDialect.HSQL).setDataSource(dataSource);
    databaseUpdateDao = configuration.getDatabaseUpdateDao();
    // TableAttribute.register(new TableAttributeHookImpl());

    // final SortedSet<UpdateEntry> updateEntries = new TreeSet<UpdateEntry>();
    // updateEntries.addAll(DatabaseCoreUpdates.getUpdateEntries(this));
    // getSystemUpdater().setUpdateEntries(updateEntries);
}

From source file:org.qi4j.library.sql.datasource.ExternalDataSourceTest.java

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    BasicDataSource externalDataSource = new BasicDataSource();
    externalDataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    externalDataSource.setUrl("jdbc:derby:memory:testdbexternal;create=true");
    // START SNIPPET: assembly
    new ExternalDataSourceAssembler(externalDataSource).visibleIn(Visibility.module)
            .identifiedBy("datasource-external-id")
            .withCircuitBreaker(DataSources.newDataSourceCircuitBreaker()).assemble(module);
    // END SNIPPET: assembly
}

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 ww . j a  v  a  2 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);// w  w w . j av a2  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);/*from w w w . j a  v a2  s .c o  m*/
    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.  ja v  a  2  s  .  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);
        }//  w  w  w .j av  a2 s.  co  m
    }

}