List of usage examples for org.apache.commons.dbcp BasicDataSource setMaxActive
public synchronized void setMaxActive(int maxActive)
From source file:com.alibaba.cobar.manager.test.ConnectionTest.java
/** * @param args/* w w w. j av a 2 s . c o m*/ */ public static void main(String[] args) { try { BasicDataSource ds = new BasicDataSource(); ds.setUsername("test"); ds.setPassword(""); ds.setUrl("jdbc:mysql://10.20.153.178:9066/"); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setMaxActive(-1); ds.setMinIdle(0); ds.setTimeBetweenEvictionRunsMillis(600000); ds.setNumTestsPerEvictionRun(Integer.MAX_VALUE); ds.setMinEvictableIdleTimeMillis(GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); Connection conn = ds.getConnection(); Statement stm = conn.createStatement(); stm.execute("show @@version"); ResultSet rst = stm.getResultSet(); rst.next(); String version = rst.getString("VERSION"); System.out.println(version); } catch (Exception exception) { System.out.println("10.20.153.178:9066 " + exception.getMessage() + exception); } }
From source file:edu.caltechUcla.sselCassel.projects.jMarkets.output.OutputWriter.java
public static void main(String[] args) { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername("jmarkets"); ds.setPassword("banana"); String dbHost = "david.ssel.caltech.edu"; String dbPort = "3306"; String dbName = "jmarkets"; ds.setUrl("jdbc:mysql://" + dbHost + ":" + dbPort + "/" + dbName); //ds.setUrl("jdbc:mysql://localhost:3306/jmarkets"); ds.setMaxActive(10); OutputWriter writer = new OutputWriter(); writer.outputSession(145, "c://output.csv"); }
From source file:com.katsu.dwm.jndi.datasource.DataSourceFactory.java
public static DataSource getDataSource(Resource resource) { BasicDataSource result = new BasicDataSource(); result.setMaxActive(resource.getMaxActive()); result.setMaxIdle(resource.getMaxIdle()); result.setPassword(resource.getPassword()); result.setUsername(resource.getUsername()); result.setUrl(resource.getUrl());//from w w w. j a v a 2 s . c om result.setDriverClassName(resource.getDriverClassName()); return result; }
From source file:ejp.examples.MultiThreadedWithConnectionPooling.java
static DataSource getDbcpDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.hsqldb.jdbcDriver"); ds.setUsername("sa"); ds.setPassword(""); ds.setMaxActive(100); ds.setUrl("jdbc:hsqldb:mem:ejp_example"); return ds;/*from ww w .j av a2 s. c o m*/ }
From source file:com.oncecorp.visa3d.bridge.utility.JdbcUtils.java
/** * This method create and returns the client data source object. In this class, * we use "Jakarta-commons-release" to create the data source object. * @param driverClass The JDBC driver class name. * @param jdbcURL The database URL.//from w ww . ja va2 s .c o m * @param jdbcUID The database user id. * @param jdbcPW The database password. * @param maxConns maximum connections * @param timeOut connection timeout * @return The data Source object. */ public static DataSource createPoolingDataSoruce(String driverClass, String jdbcURL, String jdbcUID, String jdbcPW, int maxConns, int timeOut) { try { Class.forName(driverClass); BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(driverClass); bds.setMaxActive(maxConns); bds.setMaxWait(timeOut); bds.setUrl(jdbcURL); bds.setUsername(jdbcUID); bds.setPassword(jdbcPW); System.out.println("Use dbcp pool with datasource = " + bds); return bds; } catch (Exception e) { System.out.println("Data Source creating failed. -- " + driverClass + ", " + jdbcURL + ", " + jdbcUID + ", " + jdbcPW + ", ==" + e.getMessage()); return null; } }
From source file:cn.com.sims.crawler.util.JDBCHelper.java
public static JdbcTemplate createMysqlTemplate(String templateName, String url, String username, String password, int initialSize, int maxActive) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(url);//from w w w.j a va 2 s . c o m dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive); JdbcTemplate template = new JdbcTemplate(dataSource); templateMap.put(templateName, template); return template; }
From source file:com.dangdang.ddframe.rdb.sharding.config.yaml.AbstractYamlShardingDataSourceTest.java
protected static DataSource createDataSource(final String dsName) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(org.h2.Driver.class.getName()); result.setUrl(String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL", dsName)); result.setUsername("sa"); result.setPassword(""); result.setMaxActive(100); return result; }
From source file:com.dangdang.ddframe.rdb.common.sql.base.AbstractSQLTest.java
private static BasicDataSource buildDataSource(final String dbName, final DatabaseType type) { DataBaseEnvironment dbEnv = new DataBaseEnvironment(type); BasicDataSource result = new BasicDataSource(); result.setDriverClassName(dbEnv.getDriverClassName()); result.setUrl(dbEnv.getURL(dbName)); result.setUsername(dbEnv.getUsername()); result.setPassword(dbEnv.getPassword()); result.setMaxActive(1000); if (DatabaseType.Oracle == dbEnv.getDatabaseType()) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); }//from w w w . j a v a2 s . c om return result; }
From source file:com.google.gerrit.server.schema.H2AccountPatchReviewStore.java
private static DataSource createDataSource(String url) { BasicDataSource datasource = new BasicDataSource(); datasource.setDriverClassName("org.h2.Driver"); datasource.setUrl(url);/* w ww .j a v a2 s.c o m*/ datasource.setMaxActive(50); datasource.setMinIdle(4); datasource.setMaxIdle(16); long evictIdleTimeMs = 1000 * 60; datasource.setMinEvictableIdleTimeMillis(evictIdleTimeMs); datasource.setTimeBetweenEvictionRunsMillis(evictIdleTimeMs / 2); return datasource; }
From source file:com.gs.obevo.db.impl.core.jdbc.JdbcDataSourceFactory.java
private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url, Credential credential, int numThreads, ImmutableList<String> initSqls, Properties extraConnectionProperties) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClass.getName()); dataSource.setUrl(url);//from www .j a va 2 s.c o m dataSource.setUsername(credential.getUsername()); dataSource.setPassword(credential.getPassword()); // connection pool settings dataSource.setInitialSize(numThreads); dataSource.setMaxActive(numThreads); // keep the connections open if possible; only close them via the removeAbandonedTimeout feature dataSource.setMaxIdle(numThreads); dataSource.setMinIdle(0); dataSource.setRemoveAbandonedTimeout(300); dataSource.setConnectionInitSqls(initSqls.castToList()); if (extraConnectionProperties != null) { for (String key : extraConnectionProperties.stringPropertyNames()) { dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key)); } } return dataSource; }