List of usage examples for org.apache.commons.dbcp2 BasicDataSource setUsername
public void setUsername(String username)
Sets the #username .
Note: this method currently has no effect once the pool has been initialized.
From source file:moviemanager.backend.PersonManagerTest.java
private static DataSource prepareDataSource() throws SQLException { BasicDataSource ds = new BasicDataSource(); //we will use in memory database ds.setUrl(URL);//from w w w .j a va2 s. c o m ds.setUsername("administrator"); ds.setPassword("admin"); return ds; }
From source file:dgw.mt940.db.util.DGWBasicDataSource.java
public static DataSource setupDataSource(String connectURI, String driver, String userName, String password, String removeAbandoned, String initSize, String mxSize) { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driver);//w ww. j a va 2 s. c o m ds.setUrl(connectURI); ds.setUsername(userName); ds.setPassword(password); ds.setUrl(connectURI); ds.setAbandonedUsageTracking(Boolean.getBoolean(removeAbandoned)); ds.setInitialSize(Integer.parseInt(initSize)); ds.setMaxIdle(Integer.parseInt(mxSize)); return ds; }
From source file:common.DBHelper.java
public static DataSource getDataSource() { Properties prop = new Properties(); try (InputStream input = DBHelper.class.getResourceAsStream("/config.PROPERTIES");) { prop.load(input);/*ww w . java 2s . c o m*/ } catch (IOException e) { logger.error("error reading properties", e); } BasicDataSource ds = new BasicDataSource(); ds.setUrl(prop.getProperty("dbUrl")); ds.setDriverClassName("org.apache.derby.jdbc.ClientDriver"); ds.setUsername(prop.getProperty("dbUsername")); ds.setPassword(prop.getProperty("dbPassword")); return ds; }
From source file:de.anycook.db.mysql.DBHandler.java
private static BasicDataSource setupDataSource(String server, int port, String dbName, String username, String password, int maxActive, int maxIdle) { Preconditions.checkNotNull(server);//from w w w.j av a 2 s . com Preconditions.checkNotNull(dbName); Preconditions.checkNotNull(username); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); ds.setUsername(username); if (password.length() > 0) { ds.setPassword(password); } String url = String.format("jdbc:mysql://%s:%d/%s?useConfigs=maxPerformance&useCompression=true", server, port, dbName); ds.setUrl(url); ds.setValidationQuery("SELECT 1;"); ds.setTestWhileIdle(true); ds.setTestOnReturn(true); ds.setMaxTotal(maxActive); ds.setMaxIdle(maxIdle); ds.setRemoveAbandonedOnBorrow(true); ds.setRemoveAbandonedTimeout(60); if (Configuration.getInstance().isDeveloperMode()) { ds.setLogAbandoned(true); } sLogger.info("created new Connectionpool"); return ds; }
From source file:com.rhino.data.db.DataSourceFactory.java
public static DataSource getDataSource() { if (source != null) { return source; }/*from w ww.j av a 2 s . c o m*/ Properties props = new Properties(); FileInputStream fis = null; BasicDataSource dataSource = new BasicDataSource(); try { props.load(ClassLoader.getSystemResourceAsStream("mysql.properties")); dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS")); dataSource.setUrl(props.getProperty("MYSQL_DB_URL")); dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME")); dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD")); } catch (IOException e) { throw new RuntimeException(e); } return source = dataSource; }
From source file:com.fluke.database.DatabaseProperty.java
public static DataSource getDataSource() { if (source != null) { return source; }//from w w w . j av a2s .com Properties props = new Properties(); FileInputStream fis = null; BasicDataSource dataSource = new BasicDataSource(); try { props.load(ClassLoader.getSystemResourceAsStream("config/mysql.properties")); dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS")); dataSource.setUrl(props.getProperty("MYSQL_DB_URL")); dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME")); dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD")); } catch (IOException e) { throw new RuntimeException(e); } return source = dataSource; }
From source file:com.bc.fiduceo.TestUtil.java
public static BasicDataSource getdatasourceMongoDb() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("mongodb"); dataSource.setUrl("mongodb://localhost:27017"); dataSource.setUsername("fiduceo"); dataSource.setPassword("oecudif"); return dataSource; }
From source file:de.rwth.dbis.acis.activitytracker.service.ActivityTrackerService.java
private static DataSource setupDataSource(String dbUrl, String dbUserName, String dbPassword) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(dbUrl);/*from w ww . ja va 2 s . com*/ dataSource.setUsername(dbUserName); dataSource.setPassword(dbPassword); dataSource.setValidationQuery("SELECT 1;"); dataSource.setTestOnBorrow(true); // test each connection when borrowing from the pool with the validation query dataSource.setMaxConnLifetimeMillis(1000 * 60 * 60); // max connection life time 1h. mysql drops connection after 8h. return dataSource; }
From source file:com.bc.fiduceo.TestUtil.java
public static BasicDataSource getDatasource_H2() { final BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); // the following line dumps all database interactions to the console window tb 2016-02-10 // dataSource.setUrl("jdbc:h2:mem:fiduceo;TRACE_LEVEL_SYSTEM_OUT=2"); dataSource.setUrl("jdbc:h2:mem:fiduceo"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
From source file:agency.AgencyManagerImplTest.java
private static DataSource prepareDataSource() throws SQLException, IOException { Properties myconf = new Properties(); myconf.load(Agency.class.getResourceAsStream("/myconf.properties")); BasicDataSource ds = new BasicDataSource(); ds.setUrl(myconf.getProperty("jdbc.url")); ds.setUsername(myconf.getProperty("jdbc.user")); ds.setPassword(myconf.getProperty("jdbc.password")); return ds;//w w w . j av a2s.co m }