List of usage examples for org.apache.commons.dbcp BasicDataSource setUrl
public synchronized void setUrl(String url)
Sets the #url .
Note: this method currently has no effect once the pool has been initialized.
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 www.j av a 2 s . com*/ 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:net.bioclipse.structuredb.business.StructuredbManager.java
private ApplicationContext createApplicationcontext(String databaseName, boolean local) { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( Structuredb.class.getClassLoader().getResource("applicationContext.xml").toString()); BasicDataSource dataSource = (BasicDataSource) context.getBean("dataSource"); if (local) {/* w ww. j ava 2 s .co m*/ dataSource.setUrl(HsqldbUtil.getInstance().getConnectionUrl(databaseName + ".sdb")); } else { throw new UnsupportedOperationException("non-local databases not " + "supported in this version"); } return context; }
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"); }
From source file:br.gov.frameworkdemoiselle.internal.proxy.BasicDataSourceProxy.java
private BasicDataSource getDelegate() { if (this.delegate == null) { BasicDataSource dataSource = new BasicDataSource(); try {/*w ww . ja v a 2 s . com*/ String driver = config.getDriverClass().get(dataSourceName); String url = config.getUrl().get(dataSourceName); String username = config.getUsername().get(dataSourceName); String password = config.getPassword().get(dataSourceName); dataSource.setDriverClassName(driver); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); } catch (ClassCastException cause) { throw new DemoiselleException(bundle.getString("load-duplicated-configuration-failed"), cause); } delegate = dataSource; } return this.delegate; }
From source file:edu.ucsf.vitro.opensocial.OpenSocialSmokeTests.java
/** * Check that we can connect to the database, and query one of the Shindig * tables./* w w w . j a v a 2 s . com*/ */ private void checkDatabaseTables() { BasicDataSource dataSource = null; Connection conn = null; Statement stmt = null; ResultSet rset = null; try { dataSource = new BasicDataSource(); dataSource.setDriverClassName(getProperty(PROPERTY_DB_DRIVER)); dataSource.setUrl(getProperty(PROPERTY_DB_JDBC_URL)); dataSource.setUsername(getProperty(PROPERTY_DB_USERNAME)); dataSource.setPassword(getProperty(PROPERTY_DB_PASSWORD)); conn = dataSource.getConnection(); stmt = conn.createStatement(); rset = stmt.executeQuery("select * from orng_apps"); } catch (NoSuchPropertyException e) { warnings.add(new Warning(e.getMessage())); } catch (SQLException e) { if (e.getMessage().contains("doesn't exist")) { warnings.add(new Warning("The Shindig tables don't exist " + "in the database. Was shindig_orng_tables.sql " + "run to set them up?", e)); } else { warnings.add(new Warning("Can't access the Shindig database tables", e)); } } finally { try { if (rset != null) { rset.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (stmt != null) { stmt.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:capture.PostgreSQLDatabase.java
public PostgreSQLDatabase() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DRIVER);/* w w w. j a va 2 s .com*/ 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.ibatis.common.jdbc.DbcpConfiguration.java
private BasicDataSource legacyDbcpConfiguration(Map map) { BasicDataSource basicDataSource = null; if (map.containsKey("JDBC.Driver")) { basicDataSource = new BasicDataSource(); String driver = (String) map.get("JDBC.Driver"); String url = (String) map.get("JDBC.ConnectionURL"); String username = (String) map.get("JDBC.Username"); String password = (String) map.get("JDBC.Password"); String validationQuery = (String) map.get("Pool.ValidationQuery"); String maxActive = (String) map.get("Pool.MaximumActiveConnections"); String maxIdle = (String) map.get("Pool.MaximumIdleConnections"); String maxWait = (String) map.get("Pool.MaximumWait"); basicDataSource.setUrl(url); basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); if (notEmpty(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); }//from w w w . j av a2s . c om if (notEmpty(maxActive)) { basicDataSource.setMaxActive(Integer.parseInt(maxActive)); } if (notEmpty(maxIdle)) { basicDataSource.setMaxIdle(Integer.parseInt(maxIdle)); } if (notEmpty(maxWait)) { basicDataSource.setMaxWait(Integer.parseInt(maxWait)); } Iterator props = map.keySet().iterator(); while (props.hasNext()) { String propertyName = (String) props.next(); if (propertyName.startsWith(ADD_DRIVER_PROPS_PREFIX)) { String value = (String) map.get(propertyName); basicDataSource.addConnectionProperty(propertyName.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value); } } } return basicDataSource; }
From source file:capture.MySQLDatabase.java
public MySQLDatabase() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DRIVER);//from w w w . j a v a 2s . 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.jolbox.benchmark.BenchmarkTests.java
/** * /*from www. ja va 2 s. c om*/ * * @param doPreparedStatement * @return time taken * @throws PropertyVetoException * @throws InterruptedException * @throws SQLException */ private DataSource multiThreadedDBCP(boolean doPreparedStatement) throws PropertyVetoException, InterruptedException, SQLException { BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); if (doPreparedStatement) { cpds.setPoolPreparedStatements(true); cpds.setMaxOpenPreparedStatements(max_statement); } cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); return cpds; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * //from w ww . j a va2 s.c o m * * @return time taken * @throws SQLException */ private long singleDBCP() throws SQLException { // Start DBCP BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); cpds.setMaxOpenPreparedStatements(max_statement); cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); cpds.getConnection(); // call to initialize possible lazy structures etc long start = System.currentTimeMillis(); for (int i = 0; i < MAX_CONNECTIONS; i++) { Connection conn = cpds.getConnection(); conn.close(); } long end = (System.currentTimeMillis() - start); // System.out.println("DBCP Single thread benchmark: "+end); cpds.close(); return end; }