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

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

Introduction

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

Prototype

BasicDataSource

Source Link

Usage

From source file:DynaBeansExampleV2.java

private static Connection getConnection() throws Exception {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName("com.mysql.jdbc.Driver");
    bds.setUrl("jdbc:mysql://localhost/commons");
    bds.setUsername("root");
    bds.setPassword("");

    //bds.setInitialSize(5);

    return bds.getConnection();
}

From source file:DynaBeansExampleV3.java

private static Connection getConnection() throws Exception {
    BasicDataSource bds = new BasicDataSource();
    bds.setDriverClassName("com.mysql.jdbc.Driver");
    bds.setUrl("jdbc:mysql://localhost/commons");
    bds.setUsername("root");
    bds.setPassword("");

    //      bds.setInitialSize(5);

    return bds.getConnection();
}

From source file:com.devwebsphere.wxs.jdbcloader.TestJDBCLoader.java

@BeforeClass
static void setup() throws Exception {
    Class.forName(EmbeddedDriver.class.getName());
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(EmbeddedDriver.class.getName());
    ds.setUrl("jdbc:derby:derbyDB;create=true");

    Connection connTest = ds.getConnection();
    Assert.assertNotNull(connTest);/*from www  .j  av  a  2s  . co m*/
    connTest.close();
}

From source file:ReaderManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl("jdbc:derby:memory:libraryProject;create=true");
    return dataSource;
}

From source file:com.kapti.data.persistence.oracle.OracleConnection.java

public static Connection getConnection() throws StockPlayException {
    try {//ww w. j  ava  2 s. com
        if (ds == null) {

            ds = new BasicDataSource();
            ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");

            ds.setUrl("jdbc:oracle:thin:@//oersted.iii.hogent.be:1521/xe");

            ds.setUsername("stockplay");
            ds.setPassword("chocolademousse");
            ds.setTestOnBorrow(true);
            ds.setTestOnReturn(true);
            ds.setTestWhileIdle(true);
            ds.setRemoveAbandoned(true);
            ds.setMaxWait(15 * 1000); // 15 seconden timeout
            ds.setValidationQuery("select 1 from dual");
        }

        return ds.getConnection();
    } catch (SQLException ex) {
        throw new SubsystemException(SubsystemException.Type.DATABASE_FAILURE,
                "Error while creating connection-object", ex.getCause());
    }
}

From source file:com.earldouglas.xjdl.io.JdbcLicenseLoaderTest.java

@BeforeClass
public static void setupDatabase() throws Exception {
    basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(jdbcDriver.class.getName());
    basicDataSource.setUrl("jdbc:hsqldb:mem:db");
    basicDataSource.setUsername("sa");
    basicDataSource.setPassword("");

    Connection connection = basicDataSource.getConnection();
    Statement statement = connection.createStatement();
    statement.execute("create table licenses (license varchar(512))");
}

From source file:BorrowingManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl("jdbc:derby:memory:libraryProject;create=true");
    return ds;/*w  ww  . j  av  a 2s.  c o  m*/
}

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());//from   ww  w .  ja v a 2 s .  c  om
    result.setDriverClassName(resource.getDriverClassName());
    return result;
}

From source file:ejp.examples.MultiThreadedWithConnectionPooling.java

static DataSource getDbcpDataSource() {
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName("org.hsqldb.jdbcDriver");
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setMaxActive(100);//from www.  j a  v  a  2s . c  o m
    ds.setUrl("jdbc:hsqldb:mem:ejp_example");

    return ds;
}

From source file:cz.muni.fi.pv168.dressroommanager.DressroomManagerImplTest.java

private static DataSource prepareDataSource() throws SQLException {
    BasicDataSource ds = new BasicDataSource();
    //we will use in memory database
    ds.setUrl("jdbc:derby:memory:dressroom-test;create=true");
    //ds.setUrl("jdbc:derby://localhost:1527/test");
    return ds;/*from  w  ww .  ja  va  2 s. c o  m*/
}