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:capture.PostgreSQLDatabase.java
public PostgreSQLDatabase() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DRIVER); ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username")); ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password")); ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url")); dataSource = ds;//from ww w. j av a 2s .c o m }
From source file:capture.MySQLDatabase.java
public MySQLDatabase() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DRIVER); ds.setUsername(ConfigManager.getInstance().getConfigOption("database-username")); ds.setPassword(ConfigManager.getInstance().getConfigOption("database-password")); ds.setUrl(ConfigManager.getInstance().getConfigOption("database-url")); dataSource = ds;/*from www . j a va 2s. c o m*/ }
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:com.emc.ecs.sync.source.AtmosSource.java
@Override public void parseCustomOptions(CommandLine line) { AtmosUtil.AtmosUri atmosUri = AtmosUtil.parseUri(sourceUri); endpoints = atmosUri.endpoints;/*from w ww .j a v a2s. co 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 ww 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.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.ucsf.vitro.opensocial.OpenSocialSmokeTests.java
/** * Check that we can connect to the database, and query one of the Shindig * tables.// w ww .java 2 s. c om */ 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:br.gov.frameworkdemoiselle.internal.proxy.BasicDataSourceProxy.java
private BasicDataSource getDelegate() { if (this.delegate == null) { BasicDataSource dataSource = new BasicDataSource(); try {//from ww w . jav a2 s . c o m 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: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);/* w w w .ja v a 2s. c o m*/ basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); if (notEmpty(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); } 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:com.googlecode.wmbutil.jdbc.DataSourceLocator.java
/** * Looks up a named data source/*from w ww. j a va 2s .c o m*/ * * @param dataSourceName * The name of the data source to look for * @return The data source * @throws RuntimeException * If the configuration can not be loaded or the data source * definition is missing */ public synchronized DataSource lookup(String dataSourceName) { BasicDataSource ds; if (dataSources.containsKey(dataSourceName)) { ds = (BasicDataSource) dataSources.get(dataSourceName); if (ds == null) { // we failed to create it earlier throw new RuntimeException("Failed to create data source"); } } else { ds = new BasicDataSource(); try { String driver = config.getProperty("jdbc." + dataSourceName + ".class"); if (driver == null || driver.trim().length() == 0) { throw new RuntimeException("Lookup connections configuration file must contain a jdbc." + dataSourceName + ".class value"); } else { ds.setDriverClassName(driver); } String url = config.getProperty("jdbc." + dataSourceName + ".url"); if (url == null || url.trim().length() == 0) { throw new RuntimeException("Lookup connections configuration file must contain a jdbc." + dataSourceName + ".url value"); } else { ds.setUrl(url); } String username = config.getProperty("jdbc." + dataSourceName + ".username"); if (username == null || username.trim().length() == 0) { throw new RuntimeException("Lookup connections configuration file must contain a jdbc." + dataSourceName + ".username value"); } else { ds.setUsername(username); } ds.setPassword(config.getProperty("jdbc." + dataSourceName + ".password")); ds.setDefaultReadOnly(true); dataSources.put(dataSourceName, ds); } catch (RuntimeException e) { // mark failed to create dataSources.put(dataSourceName, null); throw e; } } return ds; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * //from w w w .j a v a2s . co m * * @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; }