Example usage for org.apache.commons.dbcp BasicDataSource setUsername

List of usage examples for org.apache.commons.dbcp BasicDataSource setUsername

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource setUsername.

Prototype

public synchronized void setUsername(String username) 

Source Link

Document

Sets the #username .

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:com.dangdang.ddframe.job.example.JavaLiteJobMain.java

private static DataSource setUpEventTraceDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(EVENT_RDB_STORAGE_DRIVER);
    result.setUrl(EVENT_RDB_STORAGE_URL);
    result.setUsername(EVENT_RDB_STORAGE_USERNAME);
    result.setPassword(EVENT_RDB_STORAGE_PASSWORD);
    return result;
}

From source file:com.cgdecker.guice.jdbc.Hsqldb.java

public static DataSource getDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(jdbcDriver.class.getName());
    result.setUrl("jdbc:hsqldb:mem:.");
    result.setUsername("sa");
    result.setPassword("");
    setUpDatabase(result);/*from w  w  w  .jav  a 2 s. c  o  m*/
    return result;
}

From source file:com.weibo.datasys.parser.sql.DBConnectionFactory.java

public static void init() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(ConfigFactory.getString("jdbc.driverClassName"));
    dataSource.setUrl(ConfigFactory.getString("jdbc.url"));
    dataSource.setUsername(ConfigFactory.getString("jdbc.username"));
    dataSource.setPassword(ConfigFactory.getString("jdbc.password"));

    dataSource.setInitialSize(ConfigFactory.getInt("jdbc.initialSize", 1));
    dataSource.setMinIdle(ConfigFactory.getInt("jdbc.minIdle", 2));
    dataSource.setMaxIdle(ConfigFactory.getInt("jdbc.maxIdle", 10));
    dataSource.setMaxWait(ConfigFactory.getInt("jdbc.maxWait", 1000));
    dataSource.setMaxActive(ConfigFactory.getInt("jdbc.maxActive", 2));
    dataSource.addConnectionProperty("autoReconnect", "true");
    // ??/*from  w  w  w . jav  a2s.com*/
    dataSource.setTestWhileIdle(true);
    // ?sql?
    dataSource.setValidationQuery("select 'test'");
    // ?
    dataSource.setValidationQueryTimeout(5000);
    // 
    dataSource.setTimeBetweenEvictionRunsMillis(3600000);
    // ??
    dataSource.setMinEvictableIdleTimeMillis(3600000);

    ds = dataSource;
}

From source file:com.dangdang.ddframe.rdb.transaction.soft.AsyncJobMain.java

private static DataSource createDataSource(final String dataSourceName) {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName("com.mysql.jdbc.Driver");
    result.setUrl(String.format("jdbc:mysql://localhost:3306/%s", dataSourceName));
    result.setUsername("root");
    result.setPassword("");
    return result;
}

From source file:com.gs.obevo.db.impl.core.jdbc.JdbcDataSourceFactory.java

private static DataSource createFromJdbcUrl(Class<? extends Driver> driverClass, String url,
        Credential credential, int numThreads, ImmutableList<String> initSqls,
        Properties extraConnectionProperties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverClass.getName());
    dataSource.setUrl(url);/*from w w  w  .j a  v  a 2s .c o  m*/
    dataSource.setUsername(credential.getUsername());
    dataSource.setPassword(credential.getPassword());

    // connection pool settings
    dataSource.setInitialSize(numThreads);
    dataSource.setMaxActive(numThreads);
    // keep the connections open if possible; only close them via the removeAbandonedTimeout feature
    dataSource.setMaxIdle(numThreads);
    dataSource.setMinIdle(0);
    dataSource.setRemoveAbandonedTimeout(300);

    dataSource.setConnectionInitSqls(initSqls.castToList());
    if (extraConnectionProperties != null) {
        for (String key : extraConnectionProperties.stringPropertyNames()) {
            dataSource.addConnectionProperty(key, extraConnectionProperties.getProperty(key));
        }
    }

    return dataSource;
}

From source file:com.katsu.dwm.jndi.datasource.DataSourceFactory.java

public static DataSource getDataSource(Resource resource) {
    BasicDataSource result = new BasicDataSource();
    result.setMaxActive(resource.getMaxActive());
    result.setMaxIdle(resource.getMaxIdle());
    result.setPassword(resource.getPassword());
    result.setUsername(resource.getUsername());
    result.setUrl(resource.getUrl());/*  w  w  w  .j  av a  2s.  c  om*/
    result.setDriverClassName(resource.getDriverClassName());
    return result;
}

From source file:demo.learn.shiro.util.SqlUtil.java

/**
 * Gets the basic {@link DataSource}. Hard-coded
 * in this util. There is a script, mysql.sql, to
 * create the MySQL database.// w ww.  ja v  a 2 s  .co  m
 * @return {@link DataSource}.
 */
public static DataSource getBasicDataSource() {
    if (null == _basicDataSource) {
        BasicDataSource ds = new BasicDataSource();
        ds.setUsername("secure");
        ds.setPassword("secure#123}{");
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://mysql:3306/secure?profileSQL=false");
        ds.setMaxActive(10);

        _basicDataSource = ds;
    }
    return _basicDataSource;
}

From source file:com.flytxt.commons.reporting.connection.ConnectionProvider.java

private static DataSource getDs() {
    if (ds == null) {
        BasicDataSource bds = new BasicDataSource();
        bds.setDriverClassName(DbConnectionPropertiesProvider.getDriver());
        bds.setUrl(DbConnectionPropertiesProvider.getUrl());
        bds.setUsername(DbConnectionPropertiesProvider.getUser());
        bds.setPassword(DbConnectionPropertiesProvider.getPwd());

        // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Active : "+bds.getNumActive());
        // Logger.getLogger(ConnectionProvider.class.getName()).log(Level.INFO,"Num Idle : "+bds.getNumIdle());

        ds = bds;//w ww .  ja  v  a  2 s . com

    }

    return ds;
}

From source file:com.qcadoo.model.Utils.java

public static DataSource createDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:mem:mes");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    return dataSource;
}

From source file:com.googlecode.wmbutil.cache.LookupDataSourceFactory.java

public static synchronized LookupDataSource getDataSource() throws CacheRefreshException {
    if (dataSource == null) {
        try {//from  w  w w .j a  v  a2s  .co  m
            Properties config = new Properties();
            config.load(new FileInputStream("lookup-connection.properties"));

            BasicDataSource ds = new BasicDataSource();
            ds.setDriverClassName(config.getProperty("lookup.class"));
            ds.setUrl(config.getProperty("lookup.url"));
            ds.setUsername(config.getProperty("lookup.username"));
            ds.setPassword(config.getProperty("lookup.password"));
            ds.setDefaultReadOnly(false);

            dataSource = new JdbcLookupDataSource(ds);
        } catch (FileNotFoundException e) {
            throw new CacheRefreshException("Could not find lookup-connection.properties file", e);
        } catch (IOException e) {
            throw new CacheRefreshException("Found, but could not read from lookup-connection.properties file",
                    e);
        } catch (RuntimeException e) {
            throw new CacheRefreshException("Could not create data source", e);
        }
    }

    return dataSource;
}