List of usage examples for org.apache.commons.dbcp BasicDataSource setPassword
public synchronized void setPassword(String password)
Sets the #password .
Note: this method currently has no effect once the pool has been initialized.
From source file:com.flytxt.commons.reporting.connection.ConnectionProvider.java
private static DataSource getDs() { if (ds == null) { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(DbConnectionPropertiesProvider.getDriver()); bds.setUrl(DbConnectionPropertiesProvider.getUrl()); bds.setUsername(DbConnectionPropertiesProvider.getUser()); bds.setPassword(DbConnectionPropertiesProvider.getPwd()); // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Active : "+bds.getNumActive()); // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Idle : "+bds.getNumIdle()); ds = bds;/*from ww w .j av a 2 s . c om*/ } return ds; }
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);/* w ww. java2 s.c o m*/ return result; }
From source file:com.dangdang.ddframe.rdb.sharding.example.jdbc.Main.java
private static DataSource createDataSource(final String dataSourceName) { BasicDataSource result = new BasicDataSource(); result.setDriverClassName(com.mysql.jdbc.Driver.class.getName()); result.setUrl(String.format("jdbc:mysql://localhost:3306/%s", dataSourceName)); result.setUsername("root"); result.setPassword(""); return result; }
From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java
public static synchronized LookupDataSource getDataSource() throws CacheRefreshException { if (dataSource == null) { try {/*from w ww .j av a 2 s. c o m*/ Properties config = new Properties(); config.load(new FileInputStream("lookup-connection.properties")); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(config.getProperty("lookup.class")); ds.setUrl(config.getProperty("lookup.url")); ds.setUsername(config.getProperty("lookup.username")); ds.setPassword(config.getProperty("lookup.password")); ds.setDefaultReadOnly(false); dataSource = new JdbcLookupDataSource(ds); } catch (FileNotFoundException e) { throw new CacheRefreshException("Could not find lookup-connection.properties file", e); } catch (IOException e) { throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file", e); } catch (RuntimeException e) { throw new CacheRefreshException("Could not create data source", e); } } return dataSource; }
From source file:com.pinterest.deployservice.db.DatabaseUtil.java
/** * Create a MySQL datasource.//from w ww .jav a2 s . co m * * @param url the url of the DB. * @param user the user name to connect to MySQL as. * @param passwd the password for the corresponding MySQL user. * @param poolSize the connection pool size string, in the format of * initialSize:maxActive:maxIdle:minIdle. * @param maxWaitInMillis the max wait time in milliseconds to get a connection from the pool. * @return a BasicDataSource for the target MySQL instance. */ public static BasicDataSource createDataSource(String driverClassName, String url, String user, String passwd, String poolSize, int maxWaitInMillis) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); dataSource.setUsername(user); dataSource.setPassword(passwd); dataSource.setDefaultAutoCommit(true); dataSource.setDefaultReadOnly(false); // poolSize parsing, the poolsize string passed in the following format // initialSize:maxActive:maxIdle:minIdle String[] sizeStrs = poolSize.split(":"); dataSource.setInitialSize(Integer.parseInt(sizeStrs[0])); dataSource.setMaxActive(Integer.parseInt(sizeStrs[1])); dataSource.setMaxIdle(Integer.parseInt(sizeStrs[2])); dataSource.setMinIdle(Integer.parseInt(sizeStrs[3])); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000); dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); // dataSource.setNumTestsPerEvictionRun(3); // max wait in milliseconds for a connection. dataSource.setMaxWait(maxWaitInMillis); // force connection pool initialization. Connection conn = null; try { // Here not getting the connection from ThreadLocal no need to worry about that. conn = dataSource.getConnection(); } catch (SQLException e) { LOG.error(String.format("Failed to get a db connection when creating DataSource, url = %s", url), e); } finally { DbUtils.closeQuietly(conn); } return dataSource; }
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);//from w ww . j a v a 2 s . c o m if (DatabaseType.Oracle == dbEnv.getDatabaseType()) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); } return result; }
From source file:io.apiman.manager.test.server.ManagerApiTestServer.java
/** * Creates an in-memory datasource.// ww w .j av a2 s . c o m * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { System.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); //$NON-NLS-1$ //$NON-NLS-2$ BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); //$NON-NLS-1$ ds.setPassword(""); //$NON-NLS-1$ ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$ Connection connection = ds.getConnection(); connection.close(); System.out.println("DataSource created and bound to JNDI."); //$NON-NLS-1$ return ds; }
From source file:net.certifi.audittablegen.HsqldbDMR.java
/** * Generate a Hsqldb DataSource from Properties * * @param props//from w w w . j av a 2 s . com * @return BasicDataSource as DataSource */ static DataSource getRunTimeDataSource(Properties props) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUsername(props.getProperty("username")); dataSource.setPassword(props.getProperty("password")); dataSource.setUrl(props.getProperty("url")); dataSource.setMaxActive(10); dataSource.setMaxIdle(5); dataSource.setInitialSize(5); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setValidationQuery("SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS"); return dataSource; }
From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java
/** * Creates an in-memory datasource./*from w ww. ja va 2 s . c om*/ * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws Exception { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"); Connection connection = ds.getConnection(); connection.setAutoCommit(true); initDB(connection); connection.close(); return ds; }
From source file:edu.ncsa.uiuc.rdfrepo.testing.USeekMSailFac.java
public static IndexingSail getIndexingSail(String dburl, String dbuser, String password, String capturepredicate, Sail sail) throws SailException { //set tup the postgis datasource for indexer BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUrl(dburl);//ww w. j a va 2 s. c o m dataSource.setUsername(dbuser); dataSource.setPassword(password); PostgisIndexerSettings indexerSettings = new PostgisIndexerSettings(); // String patternString = // "?observation <http://purl.oclc.org/NET/ssnx/ssn#observationResultTime> ?time." + // "?time <http://www.w3.org/2006/time#inXSDDateTime> ?timevalue. " + // "?loc <http://www.opengis.net/rdf#hasWKT> ?coord. " + // "?sensor <http://www.loa-cnr.it/ontologies/DUL.owl#hasLocation> ?loc." + // "?observation <http://purl.oclc.org/NET/ssnx/ssn#observedBy> ?sensor. "; String patternString = "?geometry <http://www.opengis.net/rdf#hasWKT> ?wkt."; sail.initialize(); indexerSettings.setMatchSatatments(createPatternFromString(patternString, sail)); indexerSettings.setDataSource(dataSource); //a matcher decides which object should be indexed by its associated predicate, we can use "http://www.opengis.net/rdf#hasWKT" PostgisIndexMatcher matcher = new PostgisIndexMatcher(); matcher.setPredicate(capturepredicate); //create a IndexingSail from the basic sail and the indexer indexerSettings.setMatchers(Arrays.asList(new PostgisIndexMatcher[] { matcher })); // PartitionDef p = new P // IndexingSail indexingSail = new IndexingSail(sail, indexerSettings); // indexingSail.getConnection(). // indexingSail.initialize(); return null; }