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:de.siemens.quantarch.bugs.IssueTrackerParser.java
/** * Build the database connection// w ww . j a va 2s. c o m * * @return */ private DataSource buildDataSource() { // create the data source for database BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://" + projectConfig.getDbHost() + ":3306/" + projectConfig.getDbName()); dataSource.setUsername(projectConfig.getDbUser()); dataSource.setPassword(projectConfig.getDbPassword()); dataSource.setInitialSize(30); return dataSource; }
From source file:io.apiman.gateway.engine.impl.DefaultJdbcComponentTest.java
@Test public void testDataSource() throws Throwable { DefaultJdbcComponent component = new DefaultJdbcComponent(); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:testDataSource;DB_CLOSE_DELAY=-1"); try {// w ww . j av a2 s . co m IJdbcClient client = component.create(ds); doAllTests(client); } finally { try { ds.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:com.dangdang.ddframe.job.statistics.rdb.StatisticRdbRepositoryTest.java
@Before public void setup() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); repository = new StatisticRdbRepository(dataSource); }
From source file:cn.edu.seu.cose.jellyjolly.model.dao.jdbc.mysql.MysqlConnectionFactory.java
private void initDataSource() throws IOException { BasicDataSource ds = new BasicDataSource(); Properties cfgpp = new Properties(); cfgpp.load(MysqlConnectionFactory.class.getResourceAsStream("dbcp.jdbc.properties")); ds.setDriverClassName(cfgpp.getProperty("jdbc.driverClassName")); ds.setUrl(cfgpp.getProperty("jdbc.url")); ds.setUsername(cfgpp.getProperty("jdbc.username")); ds.setPassword(cfgpp.getProperty("jdbc.password")); dataSource = ds;/*from w ww. j a v a2 s. c o m*/ }
From source file:net.comze.framework.orm.datasource.DbcpDataSourceFactory.java
private BasicDataSource initialize(Properties properties) { ObjectUtils.notNull(properties, "properties"); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(properties.getProperty(JDBC_DRIVER)); basicDataSource.setUrl(properties.getProperty(JDBC_URL)); basicDataSource.setUsername(properties.getProperty(JDBC_USERNAME)); basicDataSource.setPassword(properties.getProperty(JDBC_PASSWORD)); if (properties.containsKey(DBCP_INITIALSIZE)) { basicDataSource.setInitialSize(Integer.parseInt(properties.getProperty(DBCP_INITIALSIZE))); }/* w w w .j av a2s.c o m*/ if (properties.containsKey(DBCP_MAXACTIVE)) { basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(DBCP_MAXACTIVE))); } if (properties.containsKey(DBCP_MAXIDLE)) { basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(DBCP_MAXIDLE))); } if (properties.containsKey(DBCP_MAXWAIT)) { basicDataSource.setMaxWait(Long.parseLong(properties.getProperty(DBCP_MAXWAIT))); } if (properties.containsKey(DBCP_MINEVICTABLEIDLETIMEMILLIS)) { basicDataSource.setMinEvictableIdleTimeMillis( Long.parseLong(properties.getProperty(DBCP_MINEVICTABLEIDLETIMEMILLIS))); } if (properties.containsKey(DBCP_MINIDLE)) { basicDataSource.setMinIdle(Integer.parseInt(properties.getProperty(DBCP_MINIDLE))); } if (properties.containsKey(DBCP_NUMTESTSPEREVICTIONRUN)) { basicDataSource.setNumTestsPerEvictionRun( Integer.parseInt(properties.getProperty(DBCP_NUMTESTSPEREVICTIONRUN))); } if (properties.containsKey(DBCP_REMOVEABANDONED)) { basicDataSource.setRemoveAbandoned(Boolean.parseBoolean(properties.getProperty(DBCP_REMOVEABANDONED))); } if (properties.containsKey(DBCP_REMOVEABANDONEDTIMEOUT)) { basicDataSource.setRemoveAbandonedTimeout( Integer.parseInt(properties.getProperty(DBCP_REMOVEABANDONEDTIMEOUT))); } if (properties.containsKey(DBCP_TESTONBORROW)) { basicDataSource.setTestOnBorrow(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONBORROW))); } if (properties.containsKey(DBCP_TESTONCREATE)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONCREATE))); } if (properties.containsKey(DBCP_TESTONRETURN)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONRETURN))); } if (properties.containsKey(DBCP_TESTWHILEIDLE)) { basicDataSource.setTestWhileIdle(Boolean.parseBoolean(properties.getProperty(DBCP_TESTWHILEIDLE))); } if (properties.containsKey(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)) { basicDataSource.setTimeBetweenEvictionRunsMillis( Long.parseLong(properties.getProperty(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS))); } if (properties.containsKey(DBCP_VALIDATIONQUERY)) { basicDataSource.setValidationQuery(properties.getProperty(DBCP_VALIDATIONQUERY)); } if (properties.containsKey(DBCP_VALIDATIONQUERYTIMEOUT)) { basicDataSource.setValidationQueryTimeout( Integer.parseInt(properties.getProperty(DBCP_VALIDATIONQUERYTIMEOUT))); } return basicDataSource; }
From source file:eu.peppol.jdbc.OxalisDataSourceFactoryDbcpImplTest.java
@Test public void testBasicDataSource() throws Exception { String jdbcDriverClassPath = globalConfiguration.getJdbcDriverClassPath(); URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { new URL(jdbcDriverClassPath) }, Thread.currentThread().getContextClassLoader()); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(globalConfiguration.getJdbcDriverClassName()); basicDataSource.setUrl(globalConfiguration.getJdbcConnectionURI()); basicDataSource.setUsername(globalConfiguration.getJdbcUsername()); basicDataSource.setPassword(globalConfiguration.getJdbcPassword()); // Does not work in 1.4, fixed in 1.4.1 basicDataSource.setDriverClassLoader(urlClassLoader); try {// ww w . ja v a2 s.co m Connection connection = basicDataSource.getConnection(); assertNotNull(connection); fail("Wuhu! They have finally fixed the bug in DBCP; ignoring the classloader. Consider changing the code!"); } catch (SQLException e) { // As expected when using DBCP 1.4 } }
From source file:com.widsons.spr4.conf.DataBaseConf.java
@Bean(destroyMethod = "close") public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(dbUrl);/*from w w w.j ava2s . c o m*/ dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setDriverClassName(driverClassName); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(true); dataSource.setTestWhileIdle(true); dataSource.setTimeBetweenEvictionRunsMillis(1800000); dataSource.setNumTestsPerEvictionRun(3); dataSource.setMinEvictableIdleTimeMillis(1800000); return dataSource; }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
/** * Create a HSQLDB in-memory based datasource. * * @param url//from w ww .jav a 2 s . co m * @return */ private DataSource createDataSource(final String url) { // DataSource Setup with apache commons BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl(url); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
From source file:com.googlesource.gerrit.plugins.verifystatus.server.schema.CiDataSourceProvider.java
private DataSource open(Context context, CiDataSourceType dst) { // ConfigSection dbs = new ConfigSection(cfg, "database"); String driver = config.getString("driver"); if (Strings.isNullOrEmpty(driver)) { driver = dst.getDriver();//from w w w . jav a 2 s. c om } String url = config.getString("dbUrl"); if (Strings.isNullOrEmpty(url)) { url = dst.getUrl(); } String username = config.getString("username"); String password = config.getString("password"); String interceptor = config.getString("dataSourceInterceptorClass"); boolean usePool; if (context == Context.SINGLE_USER) { usePool = false; } else { usePool = config.getBoolean("connectionpool", dst.usePool()); } if (usePool) { final BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver); ds.setUrl(url); if (username != null && !username.isEmpty()) { ds.setUsername(username); } if (password != null && !password.isEmpty()) { ds.setPassword(password); } ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT)); ds.setMinIdle(config.getInt("poolminidle", 4)); ds.setMaxIdle(config.getInt("poolmaxidle", 4)); String valueString = config.getString("poolmaxwait"); if (Strings.isNullOrEmpty(valueString)) { ds.setMaxWait(MILLISECONDS.convert(30, SECONDS)); } else { ds.setMaxWait(ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS)); } ds.setInitialSize(ds.getMinIdle()); exportPoolMetrics(ds); return intercept(interceptor, ds); } // Don't use the connection pool. try { Properties p = new Properties(); p.setProperty("driver", driver); p.setProperty("url", url); if (username != null) { p.setProperty("user", username); } if (password != null) { p.setProperty("password", password); } return intercept(interceptor, new SimpleDataSource(p)); } catch (SQLException se) { throw new ProvisionException("Database unavailable", se); } }
From source file:gov.nih.nci.cacis.xds.authz.config.JpaConfig.java
/** * Will return the Data source./*from w w w . j a v a2 s .co m*/ * * @return the data source */ @Bean(destroyMethod = "close") public DataSource dataSource() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(url); dataSource.setPassword(password); dataSource.setUsername(username); dataSource.setDriverClassName(driverClassName); return dataSource; }