List of usage examples for org.apache.commons.dbcp BasicDataSource setUsername
public synchronized void setUsername(String username)
Sets the #username .
Note: this method currently has no effect once the pool has been initialized.
From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java
/** * Creates an in-memory datasource./*from w w w .java2 s. c o m*/ * @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: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 w w . jav 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:gsn.storage.DataSources.java
public static BasicDataSource getDataSource(DBConnectionInfo dci) { BasicDataSource ds = null; try {//from ww w . j a v a 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:io.apiman.gateway.engine.policies.BasicAuthJDBCTest.java
/** * Creates an in-memory datasource./*from ww w . java 2 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: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 w w . j a v a2s . c o m 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) { //// w w w . ja v a 2 s. com // 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 w w . j ava 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:io.apiman.gateway.engine.policies.BasicAuthenticationPolicyTest.java
/** * Creates an in-memory datasource./* www.j ava 2 s . c o m*/ * @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.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();/*www .j a v a 2 s. c o m*/ }
From source file:com.ianzepp.logging.jms.service.BasicDaoTest.java
/** * TODO Method description for <code>setUpBeforeClass()</code> * //www . j av a2 s .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; }