List of usage examples for org.apache.commons.dbcp BasicDataSource setDriverClassName
public synchronized void setDriverClassName(String driverClassName)
Sets the jdbc driver class name.
Note: this method currently has no effect once the pool has been initialized.
From source file:com.uber.hoodie.cli.utils.HiveUtil.java
private static DataSource getDatasource(String jdbcUrl, String user, String pass) { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverName); ds.setUrl(jdbcUrl);/* w ww . jav a2s.c o m*/ ds.setUsername(user); ds.setPassword(pass); return ds; }
From source file:com.util.conectividad.ConectorDB.java
public static Connection obtenerConexionBasica() { Connection conexion = null;//from ww w.j a v a 2 s . c o m BasicDataSource basicDataSource = null; try { basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver"); // basicDataSource.setUrl("jdbc:oracle:thin:@192.168.21.241:1521/pdb1");// local basicDataSource.setUrl("jdbc:oracle:thin:@172.28.80.32:1525/INTERAT1");// local // basicDataSource.setUsername("interacttdp");// local basicDataSource.setUsername("USR_INTERACT_APP"); // basicDataSource.setPassword("interacttdp99");// local basicDataSource.setPassword("RT87TY"); basicDataSource.setInitialSize(5); basicDataSource.setMaxActive(2); conexion = basicDataSource.getConnection(); return conexion; } catch (Exception e) { return conexion; } finally { basicDataSource = null; conexion = null; } }
From source file:aplikasi.config.KoneksiDB.java
public static DataSource getDataSource() { BasicDataSource ds = new BasicDataSource(); ds.setUsername("root"); ds.setPassword("admin"); ds.setUrl("jdbc:mysql://localhost:3306/sipmi"); ds.setDriverClassName("org.mariadb.jdbc.Driver"); return ds;//from www . j a v a 2s. 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. 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: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);// w w w .j a va 2s . co m if (DatabaseType.Oracle == dbEnv.getDatabaseType()) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dbName)); } return result; }
From source file:com.pinterest.deployservice.db.DatabaseUtil.java
/** * Create a MySQL datasource.// w w w. j av a 2s. c om * * @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.pinterest.pinlater.backends.mysql.MySQLDataSources.java
private static DataSource createDataSource(String host, int port, String user, String passwd, int poolSize, int maxWaitMillis, int socketTimeoutMillis) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource//from w w w .ja v a 2 s . c o m .setUrl(String.format( "jdbc:mysql://%s:%d?" + "connectTimeout=5000&" + "socketTimeout=%d&" + "enableQueryTimeouts=false&" + "cachePrepStmts=true&" + "characterEncoding=UTF-8", host, port, socketTimeoutMillis)); dataSource.setUsername(user); dataSource.setPassword(passwd); dataSource.setDefaultAutoCommit(true); dataSource.setInitialSize(poolSize); dataSource.setMaxActive(poolSize); dataSource.setMaxIdle(poolSize); // deal with idle connection eviction dataSource.setValidationQuery("SELECT 1 FROM DUAL"); dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setMinEvictableIdleTimeMillis(5 * 60 * 1000); dataSource.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000); dataSource.setNumTestsPerEvictionRun(poolSize); // max wait in milliseconds for a connection. dataSource.setMaxWait(maxWaitMillis); // 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 mysql connection when creating DataSource, " + "host: %s, port: %d", host, port), e); } finally { JdbcUtils.closeConnection(conn); } return dataSource; }
From source file:io.apicurio.hub.core.editing.EditingSessionManagerTest.java
/** * Creates an in-memory datasource./*from w ww . j a v a2s .c om*/ * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:test" + (counter++) + ";DB_CLOSE_DELAY=-1"); return ds; }
From source file:net.certifi.audittablegen.HsqldbDMR.java
/** * Generate a Hsqldb DataSource from Properties * * @param props//from www . j a va 2s . co m * @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: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);//from w w w . ja v a2 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; }