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

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

Introduction

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

Prototype

public synchronized void setUrl(String url) 

Source Link

Document

Sets the #url .

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

Usage

From source file:com.greendot.db.jpa.configuration.JpaDatabaseConfiguration.java

@Bean
public DataSource dataSource() {

    final BasicDataSource dataSource = new org.apache.commons.dbcp2.BasicDataSource();
    dataSource.setDriverClassName(environment.getProperty("db.datasource.driver"));
    dataSource.setUrl(environment.getProperty("db.datasource.url"));
    dataSource.setUsername(environment.getProperty("db.datasource.username"));
    dataSource.setPassword(environment.getProperty("db.datasource.password"));

    return dataSource;
}

From source file:com.searchbox.framework.config.DataConfiguration.java

@Bean
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
    dataSource.setUrl(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
    dataSource.setUsername(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
    dataSource.setPassword(environment.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));

    return dataSource;
}

From source file:GuestManagerImplTest.java

@Before
public void setUp() throws SQLException {
    BasicDataSource bds = new BasicDataSource();
    bds.setUrl("jdbc:derby:memory:GuestManagerTest;create=true");
    this.dataSource = bds;
    //create new empty table before every test
    try (Connection conn = bds.getConnection()) {
        conn.prepareStatement("CREATE TABLE GUEST (" + "ID INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
                + "NAME VARCHAR(50)," + "CREDITCARD VARCHAR(50))").executeUpdate();
    }/*from  ww w  .j  a va 2 s. c o  m*/
    manager = new GuestManagerImpl(bds);
}

From source file:com.jf.javafx.services.Database.java

public DataSource getDataSource(String jndiName) {
    DBInfo i = infos.get(jndiName);//from  w w w.  j a  v  a 2  s  .c  om
    if (i == null) {
        return null;
    }

    DataSource ds = dss.get(jndiName);
    if (ds == null) {
        BasicDataSource t = new BasicDataSource();
        t.setDriverClassName(i.dsProvider);
        t.setUrl(i.dbUrl);
        if (!i.dbUsername.isEmpty())
            t.setUsername(i.dbUsername);
        if (!i.dbPassword.isEmpty())
            t.setPassword(i.dbPassword);

        ds = t;
        dss.put(jndiName, ds);
    }

    return ds;
}

From source file:com.cfitzarl.cfjwed.core.config.DatabaseConfigurationContainer.java

@Bean(name = "dataSource")
public DataSource dataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setPassword(password);//from  w  w  w  . ja  v  a2  s. com
    dataSource.setUsername(username);
    dataSource.setUrl(url);

    return dataSource;
}

From source file:com.microsoft.sqlserver.jdbc.connection.PoolingTest.java

/**
 * test connection pool with Apache DBCP
 * /*from  w  ww  .  jav a2  s  .  c om*/
 * @throws SQLException
 */
@Test
public void testApacheDBCP() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(connectionString);

    try {
        connect(ds);
    } finally {
        ds.close();
    }
}

From source file:io.druid.metadata.SQLFirehoseDatabaseConnector.java

protected BasicDataSource getDatasource(MetadataStorageConnectorConfig connectorConfig) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUsername(connectorConfig.getUser());
    dataSource.setPassword(connectorConfig.getPassword());
    String uri = connectorConfig.getConnectURI();
    dataSource.setUrl(uri);
    dataSource.setTestOnBorrow(true);/*from  w ww.j av a 2s . com*/
    dataSource.setValidationQuery(getValidationQuery());

    return dataSource;
}

From source file:com.thoughtworks.go.server.service.BackupServiceH2IntegrationTest.java

private BasicDataSource constructTestDataSource(File file) {
    BasicDataSource source = new BasicDataSource();
    source.setDriverClassName("org.h2.Driver");
    source.setUrl("jdbc:h2:" + file.getAbsolutePath() + "/cruise;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
    source.setUsername("sa");
    source.setPassword("");
    source.setMaxTotal(32);/*from   w  ww. j  av  a  2 s.  c om*/
    source.setMaxIdle(32);
    return source;
}

From source file:HotelManagerImplTest.java

@Before
public void setUp() throws SQLException {
    BasicDataSource bds = new BasicDataSource();
    bds.setUrl("jdbc:derby:memory:AccomManagerTest;create=true");
    this.dataSource = bds;
    //create new empty table before every test
    try (Connection conn = bds.getConnection()) {
        conn.prepareStatement("CREATE TABLE ACCOMODATION("
                + "ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY," + "GUESTID INTEGER NOT NULL,"
                + "ROOMID INTEGER NOT NULL," + "STARTDATE DATE," + "ENDDATE DATE)").executeUpdate();
    }// w  w w  .  j av  a2 s.  c  om
    try (Connection conn = bds.getConnection()) {
        conn.prepareStatement(
                "CREATE TABLE GUEST(" + "ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
                        + "NAME VARCHAR(50) NOT NULL," + "CREDITCARD VARCHAR(50))")
                .executeUpdate();
    }
    try (Connection conn = bds.getConnection()) {
        conn.prepareStatement(
                "CREATE TABLE ROOM(" + "ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,"
                        + "ROOMNUMBER INT," + "CAPACITY INT NOT NULL," + "FLOOR INT NOT NULL)")
                .executeUpdate();
    }
    accomManager = new AccomManagerImpl(bds);
    roomManager = new RoomManagerImpl(bds);
    guestManager = new GuestManagerImpl(bds);
    hotelManager = new HotelManagerImpl(bds);

}

From source file:dragonrental.backend.DbConfig.java

public DataSource dataSource() {

    Properties conf = new Properties();
    BasicDataSource ds = new BasicDataSource();
    try {/*from  w w w  . ja va  2 s  .  co  m*/
        conf.load(DbConfig.class.getResourceAsStream("/Properties.properties"));
    } catch (IOException ex) {
        //log.error("Loading properties has failed!");
    }

    ds.setUrl(conf.getProperty("db.url"));
    ds.setDriverClassName(conf.getProperty("db.driver"));
    ds.setUsername(conf.getProperty("db.user"));
    ds.setPassword(conf.getProperty("db.password"));

    DatabaseMetaData metaData;
    ResultSet tables;
    try (Connection connection = ds.getConnection()) {
        metaData = connection.getMetaData();
        tables = metaData.getTables(null, null, "%", new String[] { "TABLE" });

        //checks wheter there is any tables (will not create new tables if it finds ANY table)
        if (!tables.next()) {
            new ResourceDatabasePopulator(new ClassPathResource("schema-javadb.sql"),
                    new ClassPathResource("test-data.sql")).execute(ds);
        }
    } catch (SQLException ex) {
        System.out.println("SQL Ex when checking for tables");
        System.out.println(ex.getMessage());
    }

    return ds;
}