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:org.my.spring.batch.java.config.demo.configuration.BatchConfiguration.java
private DataSource getDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(environment.getProperty("batch.jdbc.driver")); dataSource.setUrl(environment.getProperty("batch.jdbc.url")); dataSource.setUsername(environment.getProperty("batch.jdbc.user")); dataSource.setPassword(environment.getProperty("batch.jdbc.password")); return dataSource; }
From source file:org.my.spring.batch.java.config.demo.configuration.JobSetup.java
@Bean public DataSource job1DataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(environment.getProperty("job1.jdbc.driver")); dataSource.setUrl(environment.getProperty("job1.jdbc.url")); dataSource.setUsername(environment.getProperty("job1.jdbc.user")); dataSource.setPassword(environment.getProperty("job1.jdbc.password")); return dataSource; }
From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java
private static BasicDataSource createDataSource(JdbcDatasourceInfo jdbcDatasource) throws Exception { final Properties dbcpProperties = loadDbcpProperties(); final BasicDataSource dataSource = BasicDataSourceFactory.createDataSource(dbcpProperties); dataSource.setDriverClassLoader(Thread.currentThread().getContextClassLoader()); dataSource.setDriverClassName(jdbcDatasource.getDriverClassName()); dataSource.setUrl(jdbcDatasource.getUri()); dataSource.setUsername(jdbcDatasource.getUsername()); dataSource.setPassword(jdbcDatasource.getPassword()); if (isNotEmpty(jdbcDatasource.getIsolationLevel())) { dataSource.setDefaultTransactionIsolation( TransactionIsolations.fromString(jdbcDatasource.getIsolationLevel())); }/* w w w . j a v a 2s .co m*/ if (dbcpProperties.containsKey(PROP_JMX) && Boolean.valueOf(dbcpProperties.getProperty(PROP_JMX))) { dataSource.setJmxName( ObjectName.getInstance(dbcpProperties.getProperty(PROP_MBEANNAME)).getCanonicalName()); } return dataSource; }
From source file:org.ramadda.repository.database.DatabaseManager.java
/** * _more_//from w ww. j av a 2 s . c o m * * @param connectionUrl _more_ * @param userName _more_ * @param password _more_ * * @return _more_ * * @throws Exception _more_ */ public BasicDataSource makeDataSource(String connectionUrl, String userName, String password) throws Exception { String driverClassName = loadDriver(connectionUrl); BasicDataSource ds = new BasicDataSource(); //ds.setMaxActive(getRepository().getProperty(PROP_DB_POOL_MAXACTIVE, 100)); //ds.setMaxIdle(getRepository().getProperty(PROP_DB_POOL_MAXIDLE,100)); ds.setMaxTotal(getRepository().getProperty(PROP_DB_POOL_MAXACTIVE, 100)); //30 second time out ds.setMaxWaitMillis(1000 * 30); //60 seconds ds.setRemoveAbandonedTimeout(60); //ds.setRemoveAbandoned(true); ds.setRemoveAbandonedOnBorrow(true); ds.setRemoveAbandonedOnMaintenance(true); // System.err.println("DatabaseManager.makeDataSource: url=" + connectionUrl); // System.err.println("JDBC driver class:" + driverClassName + " db type:" + dbType); ds.setDriverClassName(driverClassName); ds.setUsername(userName); ds.setPassword(password); ds.setUrl(connectionURL); /* Logger logger = getLogManager().getLogger(LOGID); if (logger != null) { ds.setLogWriter(new Log4jPrintWriter(logger)); } */ return ds; }
From source file:org.springframework.batch.sample.remotepartitioning.DataSourceConfiguration.java
@Bean public DataSource dataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(url);/*from w w w.j ava2 s.co m*/ dataSource.setUsername(username); dataSource.setPassword(password); return dataSource; }
From source file:org.wte4j.examples.showcase.server.hsql.HsqlServerBean.java
/** * create a new connection source as {@link DataSource} for this server * //from www . j a va2 s.c om * @return a new {@link DataSource} object for this server with pooled * connections * */ public synchronized DataSource createDataSource() { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl("jdbc:hsqldb:hsql://localhost/" + databaseName); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUsername("sa"); return dataSource; }
From source file:pgsql.connection.PooledConnectionFactory.java
private void initializeConnectionPool(BasicDataSource connectionPool, URI databaseUri) { final String dbUrl = "jdbc:postgresql://" + databaseUri.getHost() + databaseUri.getPath(); if (databaseUri.getUserInfo() != null) { connectionPool.setUsername(databaseUri.getUserInfo().split(":")[0]); connectionPool.setPassword(databaseUri.getUserInfo().split(":")[1]); }/*w w w . j a v a 2s. c o m*/ connectionPool.setDriverClassName("org.postgresql.Driver"); connectionPool.setUrl(dbUrl); connectionPool.setInitialSize(1); }
From source file:ro.pippo.session.jdbc.JDBCSessionDataStorageTest.java
@BeforeClass public static void setUpClass() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("org.h2.Driver"); bds.setUrl("jdbc:h2:mem:test;INIT=runscript from 'src/test/resources/create.sql'"); bds.setUsername("sa"); bds.setPassword("sa"); dataSource = bds;/*from ww w .j a v a 2 s .c o m*/ }
From source file:rzd.vivc.documentexamination.configuration.SpringDateConfigMySQL.java
@Bean //? ? /*from ww w . j a v a 2 s . c o m*/ public DataSource dataSource() { //MySQL BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("com.mysql.jdbc.Driver"); //? ds.setUrl("jdbc:mysql://localhost:3306/dateexamination"); ds.setUsername("root"); /* ds.setUsername("exam"); ds.setPassword("exam68");*/ // ds.setInitialSize(5); ds.setMaxIdle(5); ds.setMaxTotal(15); return ds; }
From source file:tilda.db.ConnectionPool.java
public static void init(String Id, String Driver, String DB, String User, String Pswd, int InitialSize, int MaxSize) { if (_DataSourcesById.get(Id) == null) synchronized (_DataSourcesById) { if (_DataSourcesById.get(Id) == null) // Definitely no connection pool by that name {//w w w . j a v a2 s .co m String Sig = DB + "``" + User; BasicDataSource BDS = _DataSourcesBySig.get(Sig); // Let's see if that DB definition is already there if (BDS == null) { LOG.info("Initializing a fresh pool for Id=" + Id + ", DB=" + DB + ", User=" + User + ", and Pswd=Shhhhhhh!"); BDS = new BasicDataSource(); BDS.setDriverClassName(Driver); BDS.setUrl(DB); if (TextUtil.isNullOrEmpty(Pswd) == false && TextUtil.isNullOrEmpty(User) == false) { BDS.setUsername(User); BDS.setPassword(Pswd); } BDS.setInitialSize(InitialSize); BDS.setMaxTotal(MaxSize); BDS.setDefaultAutoCommit(false); BDS.setDefaultTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED); BDS.setDefaultQueryTimeout(20000); _DataSourcesBySig.put(Sig, BDS); } else { LOG.info("Merging pool with ID " + Id + " into prexisting pool " + Sig); if (BDS.getInitialSize() < InitialSize) BDS.setInitialSize(InitialSize); if (BDS.getMaxTotal() < MaxSize) BDS.setMaxTotal(MaxSize); } _DataSourcesById.put(Id, BDS); } } }