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.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./*w ww.j a v a2 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:edu.ncsa.uiuc.rdfrepo.testing.USeekMSailFac.java
public static IndexingSail getIndexingSail(String dburl, String dbuser, String password, String capturepredicate, RepositorySail sail) throws SailException { //set tup the postgis datasource for indexer BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUrl(dburl);// w ww . j a v a 2 s . c o m dataSource.setUsername(dbuser); dataSource.setPassword(password); PostgisIndexerSettings indexerSettings = new PostgisIndexerSettings(); indexerSettings.setDataSource(dataSource); 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 })); return null; // PartitionDef p = new P // IndexingSail indexingSail = new IndexingSail(sail, indexerSettings); // // indexingSail.initialize(); // return indexingSail; }
From source file:io.apiman.gateway.engine.policies.BasicAuthJDBCTest.java
/** * Creates an in-memory datasource./*from ww w. j av a2 s .c om*/ * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { 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:BasicAuthJDBCTest;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$ Connection connection = ds.getConnection(); connection.prepareStatement( "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username))") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ballen', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection .prepareStatement( "CREATE TABLE roles (rolename varchar(255) NOT NULL, username varchar(255) NOT NULL)") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('user', 'bwayne')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('admin', 'bwayne')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ckent', 'user')") .executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ballen', 'user')") .executeUpdate(); connection.close(); return ds; }
From source file:gsn.storage.DataSources.java
public static BasicDataSource getDataSource(DBConnectionInfo dci) { BasicDataSource ds = null; try {//from w w w .j ava 2s . c o m ds = (BasicDataSource) GSNContext.getMainContext().lookup(Integer.toString(dci.hashCode())); if (ds == null) { ds = new BasicDataSource(); ds.setDriverClassName(dci.getDriverClass()); ds.setUsername(dci.getUserName()); ds.setPassword(dci.getPassword()); ds.setUrl(dci.getUrl()); //ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); //ds.setAccessToUnderlyingConnectionAllowed(true); GSNContext.getMainContext().bind(Integer.toString(dci.hashCode()), ds); logger.warn("Created a DataSource to: " + ds.getUrl()); } } catch (NamingException e) { logger.error(e.getMessage(), e); } return ds; }
From source file:com.plexobject.testplayer.dao.hibernate.GenericDaoHibernate.java
protected static DataSource getDataSource() { BasicDataSource source = new BasicDataSource(); source.setDriverClassName("com.mysql.jdbc.Driver"); source.setUrl("jdbc:mysql://localhost/testplayer"); source.setUsername("root"); source.setPassword("root"); source.setMaxActive(15);/*from w ww .ja v a2 s . com*/ source.setMaxIdle(4); return source; }
From source file:com.devwebsphere.jdbc.loader.JDBCTxCallback.java
public synchronized static DataSource setupDataSource(String connectURI, String user, String password) { String key = connectURI + ":" + user + ":" + password; DataSource rc = dataSourceList.get(key); if (rc == null) { ///*from w ww . j a va 2 s.c om*/ // First, we'll need a ObjectPool that serves as the // actual pool of connections. // // We'll use a GenericObjectPool instance, although // any ObjectPool implementation will suffice. // BasicDataSource bds = new BasicDataSource(); bds.setInitialSize(5); bds.setUrl(connectURI); bds.setUsername(user); bds.setPassword(password); bds.setPoolPreparedStatements(true); rc = bds; dataSourceList.put(key, bds); } return rc; }
From source file:net.hydromatic.optiq.impl.jdbc.JdbcSchema.java
/** Creates a JDBC data source with the given specification. */ public static DataSource dataSource(String url, String driverClassName, String username, String password) { if (url.startsWith("jdbc:hsqldb:")) { // Prevent hsqldb from screwing up java.util.logging. System.setProperty("hsqldb.reconfig_logging", "false"); }// w ww . ja va 2 s .co m BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setDriverClassName(driverClassName); return dataSource; }
From source file:com.dangdang.ddframe.job.event.rdb.JobEventRdbSearchTest.java
@BeforeClass public static void setUpClass() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); storage = new JobEventRdbStorage(dataSource); repository = new JobEventRdbSearch(dataSource); initStorage();//from ww w . jav a2s .c o m }
From source file:io.apiman.gateway.engine.policies.BasicAuthenticationPolicyTest.java
/** * Creates an in-memory datasource.// w w w. java 2 s . com * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { 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.prepareStatement( "CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username) )") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')") .executeUpdate(); connection.prepareStatement( "INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')") .executeUpdate(); connection.close(); return ds; }
From source file:com.ianzepp.logging.jms.service.BasicDaoTest.java
/** * TODO Method description for <code>setUpBeforeClass()</code> * /* ww w . ja v a 2s . c o m*/ * @throws SQLException */ @BeforeClass public static void setUpBeforeClass() throws SQLException { // Create the dao mapping namedQueries = new HashMap<String, String>(); namedQueries.put("FindEventById", "src/main/resources/com.ianzepp.logging.jms.service.FindEventById.sql"); namedQueries.put("InsertEvent", "src/main/resources/com.ianzepp.logging.jms.service.InsertEvent.sql"); namedQueries.put("InsertException", "src/main/resources/com.ianzepp.logging.jms.service.InsertEventException.sql"); namedQueries.put("InsertLocation", "src/main/resources/com.ianzepp.logging.jms.service.InsertEventLocation.sql"); namedQueries.put("InsertUserRequest", "src/main/resources/com.ianzepp.logging.jms.service.InsertEventUserRequest.sql"); // Create and save the datasource BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(DB_DRIVER); basicDataSource.setUrl(DB_URI); basicDataSource.setUsername(DB_USERNAME); basicDataSource.setPassword(DB_PASSWORD); dataSource = basicDataSource; }