List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword
public synchronized void setPassword(String password)
Sets the #password .
Note: this method currently has no effect once the pool has been initialized.
From source file:com.alibaba.druid.benckmark.pool.Case2.java
public void test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from www . j av 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(testOnBorrow); for (int i = 0; i < executeCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setMaxActive(maxActive);//from ww w.j av a 2s . co m dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(preparedStatementCache); dataSource.setMaxOpenPreparedStatements(preparedStatementCacheSize); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setConnectionProperties(properties); // printAV_INFO(dataSource); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.Case0.java
public void f_test_1() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w .ja v a2s . co m dataSource.setMinIdle(minIdle); dataSource.setMaxIdle(maxIdle); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < LOOP_COUNT; ++i) { p0(dataSource, "dbcp"); } System.out.println(); }
From source file:com.headstrong.fusion.services.dbpool.impl.DbPool.java
/** * package level constructor to create new dbpool instance. * /*from w w w . j a v a2s . c om*/ * @param props * properties that needs to be set for creating the pool. * @throws FusionException * Error initializing dbpool */ /* package */ DbPool(Map<String, String> props, String dbcp) throws FusionException { BasicDataSource basicDataSource = new BasicDataSource(); if (dbProps == null) { dbProps = new HashMap<String, String>(props); } if (checkMandatoryProperties(props)) { basicDataSource.setDriverClassName(props.get(FusionConstants.DATABASE_CLASSNAME)); basicDataSource.setUsername(props.get(FusionConstants.DATABASE_USERNAME)); basicDataSource.setPassword(props.get(FusionConstants.DATABASE_PASSWORD)); basicDataSource.setUrl(props.get(FusionConstants.DATABASE_URL)); basicDataSource.setMinEvictableIdleTimeMillis(this.MINEVICTABLEIDLETIMEMILLIS); basicDataSource.setTimeBetweenEvictionRunsMillis(this.TIMEBETWEENEVICTIONRUNSMILLIS); String JDBCINITIALSIZE = props.get(FusionConstants.JDBCINITIALSIZE) != null ? props.get(FusionConstants.JDBCINITIALSIZE) : dbProps.get(FusionConstants.JDBCINITIALSIZE); basicDataSource.setInitialSize(Integer.parseInt(JDBCINITIALSIZE)); String JDBCMAXACTIVE = props.get(FusionConstants.JDBCMAXACTIVE) != null ? props.get(FusionConstants.JDBCMAXACTIVE) : dbProps.get(FusionConstants.JDBCMAXACTIVE); basicDataSource.setMaxActive(Integer.parseInt(JDBCMAXACTIVE)); String JDBCMAXOPENACTIVEPREP = props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) != null ? props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) : dbProps.get(FusionConstants.JDBCMAXOPENACTIVEPREP); basicDataSource.setMaxOpenPreparedStatements(Integer.parseInt(JDBCMAXOPENACTIVEPREP)); String MINEVICTABLEIDLETIMEMILLIS = props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) != null ? props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) : dbProps.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS); basicDataSource.setMinEvictableIdleTimeMillis(Integer.parseInt(MINEVICTABLEIDLETIMEMILLIS)); String TIMEBETWEENEVICTIONRUNSMILLIS = props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) != null ? props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) : dbProps.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS); basicDataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(TIMEBETWEENEVICTIONRUNSMILLIS)); /* * if (props.get(FusionConstants.JDBCINITIALSIZE) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCINITIALSIZE))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCINITIALSIZE))); } if * (props.get(FusionConstants.JDBCMAXACTIVE) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCMAXACTIVE))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCMAXACTIVE))); } if * (props.get(FusionConstants.JDBCMAXOPENACTIVEPREP) == null) { * basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.JDBCMAXOPENACTIVEPREP))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.JDBCMAXOPENACTIVEPREP))); } * * if (props.get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS) == * null) { basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.MINEVICTABLEIDLETIMEMILLIS))); } if * (props.get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS) == * null) { basicDataSource.setInitialSize(Integer.parseInt(dbProps * .get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS))); } else { * basicDataSource.setInitialSize(Integer.parseInt(props * .get(FusionConstants.TIMEBETWEENEVICTIONRUNSMILLIS))); } */ dataSource = basicDataSource; } else { throw new FusionException("Error initializing dbpool"); } }
From source file:com.alibaba.druid.benckmark.pool.CaseKylin_mysql.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from w ww . j av a 2 s. co m*/ dataSource.setMaxIdle(maxIdle); dataSource.setMinIdle(minIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnBorrow(testWhileIdle); dataSource.setTestOnBorrow(testOnReturn); dataSource.setRemoveAbandoned(removeAbandoned); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.CaseKylin_Oracle.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from ww w . j a v a 2 s . c o m*/ dataSource.setMaxIdle(maxIdle); dataSource.setMinIdle(minIdle); dataSource.setMaxWait(maxWait); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(oracleDriverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setTestOnBorrow(testWhileIdle); dataSource.setTestOnBorrow(testOnReturn); dataSource.setRemoveAbandoned(removeAbandoned); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); dataSource.setValidationQuery(validateQuery); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:com.alibaba.druid.benckmark.pool.Case3.java
public void dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w. jav a 2 s .com dataSource.setMaxIdle(maxIdle); dataSource.setMaxWait(maxWait); dataSource.setMinIdle(minIdle); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery(validationQuery); dataSource.setTestOnBorrow(testOnBorrow); dataSource.setConnectionProperties(connectionProperties); dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); for (int i = 0; i < TEST_COUNT; ++i) { p0(dataSource, "dbcp", threadCount); } // dataSource.close(); System.out.println(); }
From source file:com.ritchey.naming.InitialContextFactory.java
/** * Create a databaseSource for a database by using properties that are * formed with the jndi name (e.g. database.myCoolDatabaseNumber1.url). url, * user, password and driver should all be defined. * * @param database is the jndi name of the database * @param properties represents the values of build.properties * @param jdbc is the context we're going to load * @throws NamingException/*from ww w. j av a2s.c om*/ */ public void createDs(String database, Properties properties, Context jdbc) throws NamingException { org.apache.commons.dbcp.BasicDataSource ds = new org.apache.commons.dbcp.BasicDataSource(); try { jdbc.bind(database, ds); } catch (Exception e) { // Quietly suppress NameAlreadyBound Exception } Boolean isDatabase = true; ds.setDriverClassName(getValue(isDatabase, "driver", database, properties)); ds.setUrl(getValue(isDatabase, "url", database, properties)); ds.setUsername(getValue(isDatabase, "user", database, properties)); ds.setPassword(getValue(isDatabase, "password", database, properties)); }
From source file:com.alfaariss.oa.util.database.jdbc.DataSourceFactory.java
private static DataSource createByConfiguration(IConfigurationManager configurationManager, Element eConfig) throws DatabaseException { BasicDataSource ds = null; try {/* w w w . jav a 2s . c om*/ ds = new BasicDataSource(); String sDriver = configurationManager.getParam(eConfig, "driver"); if (sDriver == null) { _logger.warn("No 'driver' item found in configuration"); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } ds.setDriverClassName(sDriver); String sURL = configurationManager.getParam(eConfig, "url"); if (sURL == null) { _logger.warn("No 'url' item found in configuration"); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } ds.setUrl(sURL); String sUser = configurationManager.getParam(eConfig, "username"); if (sUser == null) { _logger.warn("No 'username' item found in configuration"); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } ds.setUsername(sUser); String sPassword = configurationManager.getParam(eConfig, "password"); if (sPassword == null) { _logger.warn("No 'password' item found in configuration"); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } ds.setPassword(sPassword); addOptionalSettings(configurationManager, eConfig, ds); } catch (DatabaseException e) { throw e; } catch (Exception e) { _logger.fatal("Could not initialize object", e); throw new DatabaseException(SystemErrors.ERROR_INTERNAL); } return ds; }
From source file:com.amazon.carbonado.repo.jdbc.TestH2.java
private RepositoryBuilder jdbcBuilder(boolean isMaster) throws RepositoryException { JDBCRepositoryBuilder builder = new JDBCRepositoryBuilder(); builder.setName("jdbc"); builder.setAutoVersioningEnabled(true, null); builder.setMaster(isMaster);//w ww . j a v a 2s. com BasicDataSource ds = new BasicDataSource(); builder.setDataSource(ds); builder.setSchemaResolver(new H2SchemaResolver()); File dir = new File(TestUtilities.makeTestDirectory("jdbc"), "/h2"); String url = "jdbc:h2:" + dir.getPath(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl(url); ds.setUsername("sa"); ds.setPassword(""); return builder; }