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:org.duracloud.mill.credentials.impl.CredentialsRepoConfig.java
@Bean(name = CREDENTIALS_REPO_DATA_SOURCE_BEAN, destroyMethod = "close") public BasicDataSource credentialsRepoDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(MessageFormat.format("jdbc:mysql://{0}:{1}/{2}?autoReconnect=true", System.getProperty(ConfigConstants.MC_DB_HOST, "localhost"), System.getProperty(ConfigConstants.MC_DB_PORT, "3306"), System.getProperty(ConfigConstants.MC_DB_NAME, "mill"))); dataSource.setUsername(System.getProperty(ConfigConstants.MC_DB_USER, "mill")); dataSource.setPassword(System.getProperty(ConfigConstants.MC_DB_PASS, "password")); return dataSource; }
From source file:org.eclipse.data.sampledb.SampledbActivator.java
private DataSource getDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(DERBY_DRIVER_CLASS); ds.setUsername(SAMPLE_DB_SCHEMA);/*from ww w.java2 s . c om*/ ds.setPassword(EMPTY_VALUE); ds.setUrl(getDBUrl()); return ds; }
From source file:org.eclipse.dirigible.repository.datasource.DataSourceFacade.java
private DataSource createDirectDataSource(Properties properties) { String id = properties.getProperty(DataSourceFacade.PARAM_DB_ID); String name = properties.getProperty(DataSourceFacade.PARAM_DB_NAME); String url = properties.getProperty(DataSourceFacade.PARAM_DB_LOC); String driver = properties.getProperty(DataSourceFacade.PARAM_DB_DRIVER); String user = properties.getProperty(DataSourceFacade.PARAM_DB_USER); String password = properties.getProperty(DataSourceFacade.PARAM_DB_PASSWORD); String defaultAutoCommit = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_COMMIT); String maxActive = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_ACTIVE); String maxIdle = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_IDLE); String maxWait = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_WAIT); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUrl(url); basicDataSource.setUsername(user);//from w w w . j av a 2s. c om basicDataSource.setPassword(password); basicDataSource.setDefaultAutoCommit(Boolean.parseBoolean(defaultAutoCommit)); basicDataSource.setMaxActive(maxActive != null ? Integer.parseInt(maxActive) : 100); basicDataSource.setMaxIdle(maxIdle != null ? Integer.parseInt(maxIdle) : 30); basicDataSource.setMaxWait(maxWait != null ? Integer.parseInt(maxWait) : 10000); return basicDataSource; }
From source file:org.encuestame.test.persistence.config.DBTestConfig.java
@Bean(name = "jdbcDataSource") public BasicDataSource jdbcDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(EnMePlaceHolderConfigurer.getProperty("datasource.classname")); dataSource.setUrl(EnMePlaceHolderConfigurer.getProperty("datasource.urldb")); dataSource.setUsername(EnMePlaceHolderConfigurer.getProperty("datasource.userbd")); dataSource.setPassword(EnMePlaceHolderConfigurer.getProperty("datasource.pass")); return dataSource; }
From source file:org.eobjects.analyzer.connection.JdbcDatastore.java
public DataSource createDataSource() { initializeDriver();/*from www. ja v a 2s. c o m*/ BasicDataSource ds = new BasicDataSource(); ds.setMaxActive(-1); ds.setDefaultAutoCommit(false); ds.setUrl(_jdbcUrl); if (_username != null && _password != null) { ds.setUsername(_username); ds.setPassword(_password); } return ds; }
From source file:org.fao.geonet.arcgis.ArcSDEJdbcConnection.java
/** * * * @param connectionString An example of server string in case of Oracle * is: "jdbc:oracle:thin:@84.123.79.19:1521:orcl". * @param username the username to connect to the database. * @param password the password to connect to the database. *///from www .j a v a2 s . c o m public ArcSDEJdbcConnection(String driverName, String connectionString, String username, String password) { try { Log.debug(ARCSDE_LOG_MODULE_NAME, "Getting ArcSDE connection (via JDBC)"); BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverName); dataSource.setUrl(connectionString); dataSource.setUsername(username); dataSource.setPassword(password); // Test the connection config getting a connection and closing it. dataSource.getConnection().close(); jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); } catch (SQLException x) { Log.error(ARCSDE_LOG_MODULE_NAME, "Error getting ArcSDE connection (via JDBC)", x); throw new ExceptionInInitializerError(new ArcSDEConnectionException( "Exception in ArcSDEConnection using JDBC: can not connect to the database", x)); } }
From source file:org.ff4j.test.utils.JdbcTestHelper.java
/** * Initialize DataSource with a pool of connections to HQL database. * * @return// w ww. ja v a2 s . c o m * current data source */ public static DataSource createInMemoryHQLDataSource() { // Init DataSource BasicDataSource dbcpDataSource = new BasicDataSource(); dbcpDataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dbcpDataSource.setUsername("sa"); dbcpDataSource.setPassword(""); dbcpDataSource.setUrl("jdbc:hsqldb:mem:."); dbcpDataSource.setMaxActive(3); dbcpDataSource.setMaxIdle(2); dbcpDataSource.setInitialSize(2); dbcpDataSource.setValidationQuery("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS;"); dbcpDataSource.setPoolPreparedStatements(true); return dbcpDataSource; }
From source file:org.freewheelschedule.freewheel.config.ServerConfig.java
@Bean public BasicDataSource freewheelDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClass); dataSource.setUrl(hibernateUrl); dataSource.setUsername(hibernateUser); dataSource.setPassword(hibernatePassword); return dataSource; }
From source file:org.geosde.core.jdbc.data.datasource.DataSourceUtil.java
/** * Builds up a default DBCP DataSource that easy to use connection factories * can use to setup a connection pool./* ww w. j a v a2 s.c o m*/ * * @param url * the jdbc url * @param driverName * the jdbc driver full qualified class name * @param username * @param password * @param maxActive maximum number of concurrent connections in the pool * @param minIdle minimum number of concurrent connections in the pool * @param validationQuery * the validation query to be used for connection liveliness on * borrow, or null, if no check is to be performed * @param cachePreparedStatements * wheter to cache prepared statements or not * @return * @throws DataSourceException */ public static ManageableDataSource buildDefaultDataSource(String url, String driverName, String username, String password, int maxActive, int minIdle, String validationQuery, boolean cachePreparedStatements, int removeAbandonedTimeout) throws DataSourceException { // basics BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverName); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setAccessToUnderlyingConnectionAllowed(true); // pool size dataSource.setMaxActive(maxActive); dataSource.setMinIdle(minIdle); // pool eviction settings dataSource.setMinEvictableIdleTimeMillis(1000 * 20); dataSource.setTimeBetweenEvictionRunsMillis(1000 * 10); // connection validation if (validationQuery != null) { dataSource.setTestOnBorrow(true); dataSource.setValidationQuery(validationQuery); } // prepared statement cache if (cachePreparedStatements) { dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(10); } // remove abandoned connections (I know it's deprecated, but we do want // something shaving off lost connections. Let's give them 5 minutes of // continuous usage if (removeAbandonedTimeout > 0) { dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); dataSource.setLogAbandoned(true); } Connection conn = null; try { conn = dataSource.getConnection(); } catch (Exception e) { throw new DataSourceException("Connection test failed ", e); } finally { if (conn != null) try { conn.close(); } catch (SQLException e) { } } return new DBCPDataSource(dataSource); }
From source file:org.geosde.core.jdbc.data.datasource.DBCPDataSourceFactory.java
public DataSource createNewDataSource(Map params) throws IOException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName((String) DRIVERCLASS.lookUp(params)); dataSource.setUrl((String) JDBC_URL.lookUp(params)); dataSource.setUsername((String) USERNAME.lookUp(params)); dataSource.setPassword((String) PASSWORD.lookUp(params)); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMaxActive(((Integer) MAXACTIVE.lookUp(params)).intValue()); dataSource.setMaxIdle(((Integer) MAXIDLE.lookUp(params)).intValue()); // check the data source is properly setup by trying to gather a connection out of it Connection conn = null;/* ww w . j a va2 s .c o m*/ try { conn = dataSource.getConnection(); } catch (SQLException e) { throw new DataSourceException("Connection pool improperly set up: " + e.getMessage(), e); } finally { // close the connection at once if (conn != null) try { conn.close(); } catch (SQLException e) { } } return dataSource; }