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

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

Introduction

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

Prototype

public synchronized void setUsername(String username) 

Source Link

Document

Sets the #username .

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

Usage

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

}

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

/**
 * Create datasource by dbsettign//from w w  w.ja  v  a2 s . c o  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;
}

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

/**
 * dataSourcedbcp??//from  w ww. j  a  va 2  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);
    dataSource.setPassword(password);/*www. j  av  a 2s . com*/
    dataSource.setUrl(url);
    return dataSource;
}