List of usage examples for org.apache.commons.dbcp BasicDataSource setDriverClassName
public synchronized void setDriverClassName(String driverClassName)
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been initialized.
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 w w w . j a v a2s .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.mirth.connect.connectors.jdbc.JdbcConnector.java
private void setupDataSource(String address, String driver, String username, String password) { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); basicDataSource.setUrl(address);/*from www . j av a 2 s . c o m*/ dataSource = basicDataSource; }
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 . j a va 2 s .c o m 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.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 a v a2 s .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:blueprint.sdk.experimental.florist.db.ConnectionListener.java
public void contextInitialized(final ServletContextEvent arg0) { Properties poolProp = new Properties(); try {// ww w .ja 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.Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w.j a v a 2 s . c o 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.alibaba.druid.benckmark.pool.Case1.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);/*from w ww . j a va2s .c o 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); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java
private DataSource getDbDataSource() { String url = null;// www . j a v a 2 s.c om String username = null; String password = null; if (ebaoProp.containsKey("url")) { url = ebaoProp.getProperty("url"); } if (ebaoProp.containsKey("username")) { username = ebaoProp.getProperty("username"); } if (ebaoProp.containsKey("password")) { password = ebaoProp.getProperty("password"); } BasicDataSource bds = new BasicDataSource(); bds.setUrl(url); bds.setUsername(username); bds.setPassword(password); bds.setDriverClassName("oracle.jdbc.driver.OracleDriver"); return bds; }
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 {//from w ww. ja v a2s .c o m this.connection = ds.getConnection(); } catch (SQLException e) { throw new HoodieHiveSyncException( "Cannot create hive connection " + getHiveJdbcUrlWithDefaultDBName(), e); } } }
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);/*from w w w . ja v a2 s.co m*/ 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; }