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

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

Introduction

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

Prototype

public synchronized void setPassword(String password) 

Source Link

Document

Sets the #password .

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

Usage

From source file:edu.si.services.sidora.rest.batch.BatchServiceTest.java

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry reg = super.createRegistry();

    if (USE_MYSQL_DB) {
        BasicDataSource testMySQLdb = new BasicDataSource();
        testMySQLdb.setDriverClassName("com.mysql.jdbc.Driver");
        testMySQLdb.setUrl(// ww w  .j  a  v a  2 s  . c o m
                "jdbc:mysql://" + props.getProperty("mysql.host") + ":" + props.getProperty("mysql.port") + "/"
                        + props.getProperty("mysql.database") + "?zeroDateTimeBehavior=convertToNull");
        testMySQLdb.setUsername(props.getProperty("mysql.username").toString());
        testMySQLdb.setPassword(props.getProperty("mysql.password").toString());
        reg.bind("dataSource", testMySQLdb);
    } else {
        reg.bind("dataSource", db);
    }

    reg.bind("dataSource", db);

    reg.bind("jsonProvider", org.apache.cxf.jaxrs.provider.json.JSONProvider.class);
    reg.bind("jaxbProvider", org.apache.cxf.jaxrs.provider.JAXBElementProvider.class);

    return reg;
}

From source file:capture.PostgreSQLDatabase.java

public PostgreSQLDatabase() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(DRIVER);/*from w  w  w  .  ja v  a 2  s  .c  o  m*/
    ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username"));
    ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password"));
    ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url"));
    dataSource = ds;
}

From source file:blueprint.sdk.experimental.florist.db.ConnectionListener.java

public void contextInitialized(final ServletContextEvent arg0) {
    Properties poolProp = new Properties();
    try {//from www . j a  va  2  s  .  c om
        Context initContext = new InitialContext();

        // load pool properties file (from class path)
        poolProp.load(ConnectionListener.class.getResourceAsStream("/jdbc_pools.properties"));
        StringTokenizer stk = new StringTokenizer(poolProp.getProperty("PROP_LIST"));

        // process all properties files list in pool properties (from class
        // path)
        while (stk.hasMoreTokens()) {
            try {
                String propName = stk.nextToken();
                LOGGER.info(this, "loading jdbc properties - " + propName);

                Properties prop = new Properties();
                prop.load(ConnectionListener.class.getResourceAsStream(propName));

                DataSource dsr;
                if (prop.containsKey("JNDI_NAME")) {
                    // lookup DataSource from JNDI
                    // FIXME JNDI support is not tested yet. SPI or Factory
                    // is needed here.
                    LOGGER.warn(this, "JNDI DataSource support needs more hands on!");
                    dsr = (DataSource) initContext.lookup(prop.getProperty("JNDI_NAME"));
                } else {
                    // create new BasicDataSource
                    BasicDataSource bds = new BasicDataSource();
                    bds.setMaxActive(Integer.parseInt(prop.getProperty("MAX_ACTIVE")));
                    bds.setMaxIdle(Integer.parseInt(prop.getProperty("MAX_IDLE")));
                    bds.setMaxWait(Integer.parseInt(prop.getProperty("MAX_WAIT")));
                    bds.setInitialSize(Integer.parseInt(prop.getProperty("INITIAL")));
                    bds.setDriverClassName(prop.getProperty("CLASS_NAME"));
                    bds.setUrl(prop.getProperty("URL"));
                    bds.setUsername(prop.getProperty("USER"));
                    bds.setPassword(prop.getProperty("PASSWORD"));
                    bds.setValidationQuery(prop.getProperty("VALIDATION"));
                    dsr = bds;
                }
                boundDsrs.put(prop.getProperty("POOL_NAME"), dsr);
                initContext.bind(prop.getProperty("POOL_NAME"), dsr);
            } catch (RuntimeException e) {
                LOGGER.trace(e);
            }
        }
    } catch (IOException | NamingException e) {
        LOGGER.trace(e);
    }
}

From source file:com.alibaba.druid.benckmark.pool.Case1.java

public void test_dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from  ww w. ja  v a 2 s. c  om*/
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(false);

    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.uber.hoodie.hive.HoodieHiveClient.java

private void createHiveConnection() {
    if (connection == null) {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(driverName);
        ds.setUrl(getHiveJdbcUrlWithDefaultDBName());
        ds.setUsername(syncConfig.hiveUser);
        ds.setPassword(syncConfig.hivePass);
        LOG.info("Getting Hive Connection from Datasource " + ds);
        try {//w  w  w  . j  av a  2 s .c  o  m
            this.connection = ds.getConnection();
        } catch (SQLException e) {
            throw new HoodieHiveSyncException(
                    "Cannot create hive connection " + getHiveJdbcUrlWithDefaultDBName(), e);
        }
    }
}

From source file:capture.MySQLDatabase.java

public MySQLDatabase() {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(DRIVER);//from  w w w .j a v  a2  s  .  c o  m
    ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username"));
    ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password"));
    ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url"));
    dataSource = ds;
}

From source file:com.alibaba.druid.benckmark.pool.Case4.java

public void test_dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);/*from  w  w  w .  ja v  a2 s . co  m*/
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(false);

    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
}

From source file:com.emc.ecs.sync.source.AtmosSource.java

@Override
public void parseCustomOptions(CommandLine line) {
    AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri);
    endpoints = atmosUri.endpoints;// w w  w  . ja  va 2 s .c  o  m
    uid = atmosUri.uid;
    secret = atmosUri.secret;
    namespaceRoot = atmosUri.rootPath;

    if (line.hasOption(SOURCE_OIDLIST_OPTION))
        oidFile = line.getOptionValue(SOURCE_OIDLIST_OPTION);

    if (line.hasOption(SOURCE_NAMELIST_OPTION))
        nameFile = line.getOptionValue(SOURCE_NAMELIST_OPTION);

    if (line.hasOption(SOURCE_SQLQUERY_OPTION)) {
        query = line.getOptionValue(SOURCE_SQLQUERY_OPTION);

        // Initialize a connection pool
        BasicDataSource ds = new BasicDataSource();
        ds.setUrl(line.getOptionValue(JDBC_URL_OPT));
        if (line.hasOption(JDBC_DRIVER_OPT))
            ds.setDriverClassName(line.getOptionValue(JDBC_DRIVER_OPT));
        ds.setUsername(line.getOptionValue(JDBC_USER_OPT));
        ds.setPassword(line.getOptionValue(JDBC_PASSWORD_OPT));
        ds.setMaxActive(200);
        ds.setMaxOpenPreparedStatements(180);
        setDataSource(ds);
    }

    deleteTags = line.hasOption(DELETE_TAGS_OPT);
}

From source file:com.alibaba.druid.benckmark.pool.PoolPerformanceTest.java

@Test
public void test_dbcp() throws Exception {
    final BasicDataSource dataSource = new BasicDataSource();

    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);//from  w w w.  j a  v  a2s .  co m
    dataSource.setMinIdle(minPoolSize);
    dataSource.setMaxIdle(maxPoolSize);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(false);
    System.out.println(dataSource.getClass().getSimpleName());
    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "dbcp", threadCount);
    }
    System.out.println();
    dataSource.close();
    TestDriver.instance.reset();
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexerSettings.java

@Override
public void initProperties(Properties properties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(properties.getProperty("provider", "org.postgresql.Driver"));
    dataSource.setUrl(properties.getProperty("url"));
    dataSource.setUsername(properties.getProperty("username"));
    dataSource.setPassword(properties.getProperty("password"));
    this.setDataSource(dataSource);
    this.setIndexGraph((IndexGraph) properties.get("index-graph"));
    this.tableName = properties.getProperty("index-table");
}