Example usage for org.apache.commons.dbcp2 BasicDataSource BasicDataSource

List of usage examples for org.apache.commons.dbcp2 BasicDataSource BasicDataSource

Introduction

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

Prototype

BasicDataSource

Source Link

Usage

From source file:com.haulmont.cuba.testsupport.TestDataSource.java

public TestDataSource(String connUrl, String user, String password) {
    dataSource = new BasicDataSource();
    dataSource.setUrl(connUrl);// www  .  j  a  v  a 2 s .com
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setMaxTotal(20);
}

From source file:br.edu.ifpb.padroes.projeto.sisbiblioteca.dao.ConnectionProvider.java

public Connection getConnection() throws ClassNotFoundException, SQLException {

    if (connectionPool == null || connectionPool.isClosed()) {

        try {//from  ww w . j  av a2s .  com

            connectionPool = new BasicDataSource();
            connectionPool.setUsername(username);
            connectionPool.setPassword(password);
            connectionPool.setDriverClassName(driver);
            connectionPool.setUrl(url);

        } catch (IndexOutOfBoundsException ex) {
            connectionPool.close();
            return null;
        }

    }

    return connectionPool.getConnection();
}

From source file:com.tamnd.app.config.DataSourceConfig.java

@Bean
public DataSource mysqlDataSource() {
    String _user = "root";
    String _password = "123456";
    String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&maxReconnects=10&";

    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(url);//from  w w w.j a v a  2 s . co  m
    dataSource.setUsername(_user);
    dataSource.setPassword(_password);
    return dataSource;
}

From source file:cz.fi.muni.pv168.SpringConfig.java

@Bean
public DataSource dataSource() {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(env.getProperty("jdbc.driver"));
    bds.setUrl(env.getProperty("jdbc.url"));
    bds.setUsername(env.getProperty("jdbc.user"));
    bds.setPassword(env.getProperty("jdbc.password"));
    return bds;/*from w  w  w  . j  a v a2 s  .co m*/
}

From source file:co.id.ipb.ilkom.training.db.SpringDataJpaConfiguration.java

@Bean
DataSource dataSource() {//from www . ja  v  a 2s. c  o m
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:mysql://localhost:3306/trainingjava");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    dataSource.setInitialSize(20);
    dataSource.setMaxIdle(20);
    dataSource.setMaxTotal(100);
    return dataSource;
}

From source file:com.vaadin.tutorial.todomvc.TodoModel.java

private static DataSource getDataSource() {
    if (dataSource == null) {
        synchronized (TodoModel.class) {
            // Standard double check trick to avoid double initialization
            // in case of race conditions
            if (dataSource == null) {
                dataSource = new BasicDataSource();
                dataSource.setUrl("jdbc:hsqldb:mem:tododb");
                dataSource.setUsername("SA");
                dataSource.setPassword("");
                try (Connection connection = dataSource.getConnection()) {
                    setupDatabase(connection);
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }//from   w w  w  .  ja v a2 s . c o  m
            }
        }
    }
    return dataSource;
}

From source file:com.ebay.pulsar.analytics.metricstore.db.RDMBSTest.java

@SuppressWarnings("unchecked")
@Test/*from   ww  w  . jav  a 2 s .  c o m*/
public void testRDBMS() {
    String driver2 = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://locahost:3306/test";
    String userName = "root";
    String userPwd = "";
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName(driver2);
    bds.setUrl(url);
    bds.setUsername(userName);
    bds.setPassword(userPwd);
    DBFactory.setDs(bds);
    List<String> result = new ArrayList<String>();
    result.add("result");
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = Mockito.mock(NamedParameterJdbcTemplate.class);
    when(namedParameterJdbcTemplate.query(Matchers.anyString(), Matchers.any(Map.class),
            Matchers.any(ResultSetExtractor.class))).thenReturn(result);
    RDBMS db = new RDBMS(driver2, url, userName, userPwd);
    db.setDriver(driver2);
    db.setNamedParameterJdbcTemplate(namedParameterJdbcTemplate);
    db.setUrl(url);
    db.setUserName(userName);
    db.setUserPwd(userPwd);
    assertEquals(namedParameterJdbcTemplate, db.getNamedParameterJdbcTemplate());
    Map<String, String> map = new HashMap<String, String>();
    assertTrue(result.equals(db.queryForList("test", map, 10)));

}

From source file:br.edu.claudivan.controledegastos.dao.utils.DatabaseUtils.java

private void createDataSource() {
    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(databaseProperties.getProperty(DRIVER_CLASS_NAME_KEY));
    dataSource.setUrl(databaseProperties.getProperty(DB_URL_KEY));
    dataSource.setUsername(databaseProperties.getProperty(DB_USERNAME_KEY));
    dataSource.setPassword(databaseProperties.getProperty(DB_PASSWORD_KEY));

    dataSource.setInitialSize(3);/*  ww w . j  a  v a2s .c o  m*/
    dataSource.setMaxIdle(3);
    dataSource.setMaxTotal(10);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(180);
    dataSource.setMaxWaitMillis(5000);
    dataSource.setLogExpiredConnections(true);
    dataSource.setLogAbandoned(true);
}

From source file:com.mycompany.configuration.SpringDateConfigMySQL.java

@Bean
//? ? /* w  ww .j  a  va  2s .c o m*/
public DataSource dataSource() {
    //MySQL
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    //? 
    ds.setUrl("jdbc:mysql://localhost:3306/dateexam");
    ds.setUsername("root");
    ds.setPassword("root");
    /* ds.setUsername("exam");
    ds.setPassword("exam68");*/
    //
    ds.setInitialSize(5);
    ds.setMaxIdle(5);
    ds.setMaxTotal(15);

    return ds;
}

From source file:moviemanager.backend.RelationshipManagerTest.java

private DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();

    ds.setUrl(URL);
    return ds;
}