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:com.alibaba.druid.benckmark.pool.Case4.java
public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);// w w w .j a v a 2s. c o m dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(maxOpenPreparedStatements); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); }
From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexerSettings.java
@Override public void initProperties(Properties properties) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(properties.getProperty("provider", "org.postgresql.Driver")); dataSource.setUrl(properties.getProperty("url")); dataSource.setUsername(properties.getProperty("username")); dataSource.setPassword(properties.getProperty("password")); this.setDataSource(dataSource); this.setIndexGraph((IndexGraph) properties.get("index-graph")); this.tableName = properties.getProperty("index-table"); }
From source file:com.alibaba.druid.benckmark.pool.PoolPerformanceTest.java
@Test public void test_dbcp() throws Exception { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive);//from w w w . ja v a 2 s .co m dataSource.setMinIdle(minPoolSize); dataSource.setMaxIdle(maxPoolSize); dataSource.setPoolPreparedStatements(true); dataSource.setDriverClassName(driverClass); dataSource.setUrl(jdbcUrl); dataSource.setPoolPreparedStatements(true); dataSource.setUsername(user); dataSource.setPassword(password); dataSource.setValidationQuery("SELECT 1"); dataSource.setTestOnBorrow(false); System.out.println(dataSource.getClass().getSimpleName()); for (int i = 0; i < loopCount; ++i) { p0(dataSource, "dbcp", threadCount); } System.out.println(); dataSource.close(); TestDriver.instance.reset(); }
From source file:br.gov.frameworkdemoiselle.internal.proxy.BasicDataSourceProxy.java
private BasicDataSource getDelegate() { if (this.delegate == null) { BasicDataSource dataSource = new BasicDataSource(); try {// w ww . j a v a2s . c o m String driver = config.getDriverClass().get(dataSourceName); String url = config.getUrl().get(dataSourceName); String username = config.getUsername().get(dataSourceName); String password = config.getPassword().get(dataSourceName); dataSource.setDriverClassName(driver); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); } catch (ClassCastException cause) { throw new DemoiselleException(bundle.getString("load-duplicated-configuration-failed"), cause); } delegate = dataSource; } return this.delegate; }
From source file:edu.ucsf.vitro.opensocial.OpenSocialSmokeTests.java
/** * Check that we can connect to the database, and query one of the Shindig * tables.// w w w . java2 s . c o m */ private void checkDatabaseTables() { BasicDataSource dataSource = null; Connection conn = null; Statement stmt = null; ResultSet rset = null; try { dataSource = new BasicDataSource(); dataSource.setDriverClassName(getProperty(PROPERTY_DB_DRIVER)); dataSource.setUrl(getProperty(PROPERTY_DB_JDBC_URL)); dataSource.setUsername(getProperty(PROPERTY_DB_USERNAME)); dataSource.setPassword(getProperty(PROPERTY_DB_PASSWORD)); conn = dataSource.getConnection(); stmt = conn.createStatement(); rset = stmt.executeQuery("select * from orng_apps"); } catch (NoSuchPropertyException e) { warnings.add(new Warning(e.getMessage())); } catch (SQLException e) { if (e.getMessage().contains("doesn't exist")) { warnings.add(new Warning("The Shindig tables don't exist " + "in the database. Was shindig_orng_tables.sql " + "run to set them up?", e)); } else { warnings.add(new Warning("Can't access the Shindig database tables", e)); } } finally { try { if (rset != null) { rset.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (stmt != null) { stmt.close(); } } catch (Exception e) { e.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.ibatis.common.jdbc.DbcpConfiguration.java
private BasicDataSource legacyDbcpConfiguration(Map map) { BasicDataSource basicDataSource = null; if (map.containsKey("JDBC.Driver")) { basicDataSource = new BasicDataSource(); String driver = (String) map.get("JDBC.Driver"); String url = (String) map.get("JDBC.ConnectionURL"); String username = (String) map.get("JDBC.Username"); String password = (String) map.get("JDBC.Password"); String validationQuery = (String) map.get("Pool.ValidationQuery"); String maxActive = (String) map.get("Pool.MaximumActiveConnections"); String maxIdle = (String) map.get("Pool.MaximumIdleConnections"); String maxWait = (String) map.get("Pool.MaximumWait"); basicDataSource.setUrl(url);/* w ww . j av a2 s. c o m*/ basicDataSource.setDriverClassName(driver); basicDataSource.setUsername(username); basicDataSource.setPassword(password); if (notEmpty(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); } if (notEmpty(maxActive)) { basicDataSource.setMaxActive(Integer.parseInt(maxActive)); } if (notEmpty(maxIdle)) { basicDataSource.setMaxIdle(Integer.parseInt(maxIdle)); } if (notEmpty(maxWait)) { basicDataSource.setMaxWait(Integer.parseInt(maxWait)); } Iterator props = map.keySet().iterator(); while (props.hasNext()) { String propertyName = (String) props.next(); if (propertyName.startsWith(ADD_DRIVER_PROPS_PREFIX)) { String value = (String) map.get(propertyName); basicDataSource.addConnectionProperty(propertyName.substring(ADD_DRIVER_PROPS_PREFIX_LENGTH), value); } } } return basicDataSource; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * //from ww w . j av a 2 s . c o m * * @param doPreparedStatement * @return time taken * @throws PropertyVetoException * @throws InterruptedException * @throws SQLException */ private DataSource multiThreadedDBCP(boolean doPreparedStatement) throws PropertyVetoException, InterruptedException, SQLException { BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); if (doPreparedStatement) { cpds.setPoolPreparedStatements(true); cpds.setMaxOpenPreparedStatements(max_statement); } cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); return cpds; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * // w ww . j a v a 2 s . co m * * @return time taken * @throws SQLException */ private long singleDBCP() throws SQLException { // Start DBCP BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); cpds.setMaxOpenPreparedStatements(max_statement); cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); cpds.getConnection(); // call to initialize possible lazy structures etc long start = System.currentTimeMillis(); for (int i = 0; i < MAX_CONNECTIONS; i++) { Connection conn = cpds.getConnection(); conn.close(); } long end = (System.currentTimeMillis() - start); // System.out.println("DBCP Single thread benchmark: "+end); cpds.close(); return end; }
From source file:com.jolbox.benchmark.BenchmarkTests.java
/** * Benchmarks PreparedStatement functionality (single thread) * @return result/* w w w . ja v a 2s .c o m*/ * * @throws PropertyVetoException * @throws SQLException */ private long testPreparedStatementSingleThreadDBCP() throws PropertyVetoException, SQLException { BasicDataSource cpds = new BasicDataSource(); cpds.setDriverClassName("com.jolbox.bonecp.MockJDBCDriver"); cpds.setUrl(url); cpds.setUsername(username); cpds.setPassword(password); cpds.setMaxIdle(-1); cpds.setMinIdle(-1); cpds.setPoolPreparedStatements(true); cpds.setMaxOpenPreparedStatements(30); cpds.setInitialSize(pool_size); cpds.setMaxActive(pool_size); Connection conn = cpds.getConnection(); long start = System.currentTimeMillis(); for (int i = 0; i < MAX_CONNECTIONS; i++) { Statement st = conn.prepareStatement(TEST_QUERY); st.close(); } conn.close(); long end = (System.currentTimeMillis() - start); System.out.println("DBCP PreparedStatement Single thread benchmark: " + end); results.add("DBCP, " + end); // dispose of pool cpds.close(); return end; }
From source file:fi.ni.IFC_ClassModel.java
public void listRDF(OutputStream outputStream, String path, VirtConfig virt) throws IOException, SQLException { BufferedWriter out = null;//from ww w . j ava2 s. c o m Connection c = null; String prefix_query = "PREFIX : <" + path + "> " + "PREFIX instances: <http://drum.cs.hut.fi/instances#> " + "PREFIX owl: <" + Namespace.OWL + "> " + "PREFIX ifc: <" + Namespace.IFC + "> " + "PREFIX xsd: <" + Namespace.XSD + "> " + "INSERT IN GRAPH <" + path + "> { "; try { //Setup file output out = new BufferedWriter(new OutputStreamWriter(outputStream)); out.write("@prefix : <" + path + ">.\n"); out.write("@prefix instances: <http://drum.cs.hut.fi/instances#>. \n"); out.write("@prefix owl: <" + Namespace.OWL + "> .\n"); out.write("@prefix ifc: <" + Namespace.IFC + "> .\n"); out.write("@prefix xsd: <" + Namespace.XSD + "> .\n"); out.write("\n"); //If necessary, setup virtuoso connection if (virt != null) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUsername(virt.user); dataSource.setPassword(virt.password); dataSource.setUrl(virt.jdbc_uri); dataSource.setMaxActive(100); dataSource.setDriverClassName("virtuoso.jdbc4.Driver"); c = dataSource.getConnection(); } for (Map.Entry<Long, Thing> entry : object_buffer.entrySet()) { Thing gobject = entry.getValue(); String triples = generateTriples(gobject); out.write(triples); if (virt != null) { Statement stmt = c.createStatement(); StringBuilder queryString = new StringBuilder(); queryString.append(prefix_query); queryString.append(triples); queryString.append("}"); boolean more = stmt.execute("sparql " + queryString.toString()); if (!more) { System.err.println("INSERT failed."); } if (stmt != null) stmt.close(); } } } finally { if (out != null) out.close(); if (c != null) c.close(); } }