Search in sources :

Example 6 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project OpenAttestation by OpenAttestation.

the class Derby method getDataSource.

public static DataSource getDataSource() throws SQLException {
    if (!isLoaded) {
        startDatabase();
    }
    if (ds == null) {
        BasicDataSource dataSource = new BasicDataSource();
        // or com.mysql.jdbc.Driver  for mysql
        dataSource.setDriverClassName(driver);
        //        dataSource.setUsername("username");
        //        dataSource.setPassword("password");
        //dataSource.setUrl("jdbc:derby:mytestdb;create=true"); // automatically creates derby in-memory db,   or use "jdbc:mysql://<host>:<port>/<database>"  for a mysql db
        // creates it in the "target/derby" folder which is for temporary files, good for junit tests
        dataSource.setUrl(protocol + ";create=true");
        dataSource.setMaxActive(10);
        dataSource.setMaxIdle(5);
        dataSource.setInitialSize(5);
        // derby-specific query,  for mysql /postgresl / microsoft sql / sqlite / and h2  use "select 1"
        dataSource.setValidationQuery("VALUES 1");
        ds = dataSource;
    }
    return ds;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 7 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project OpenAttestation by OpenAttestation.

the class JdbcUtil method getDataSource.

public static DataSource getDataSource() {
    try {
        if (ds == null) {
            //String driver = My.jdbc().driver();
            //String dbUrl = My.jdbc().url();
            String driver = ASConfig.getASDataJpaProperties().getProperty("javax.persistence.jdbc.driver");
            String dbUrl = ASConfig.getASDataJpaProperties().getProperty("javax.persistence.jdbc.url");
            BasicDataSource dataSource = new BasicDataSource();
            // or com.mysql.jdbc.Driver  for mysql
            dataSource.setDriverClassName(driver);
            dataSource.setUrl(dbUrl);
            //dataSource.setUsername(My.configuration().getDatabaseUsername());
            //dataSource.setPassword(My.configuration().getDatabasePassword());
            dataSource.setUsername(ASConfig.getDatabaseUsername());
            dataSource.setPassword(ASConfig.getDatabasePassword());
            ds = dataSource;
        }
    } catch (Exception ex) {
        log.error("Error connecting to the database. {}", ex.getMessage());
    }
    return ds;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) SQLException(java.sql.SQLException)

Example 8 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project sharding-jdbc by dangdangdotcom.

the class YamlShardingDataSourceTest method createDataSource.

private DataSource createDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(Driver.class.getName());
    result.setUrl("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL");
    result.setUsername("sa");
    result.setPassword("");
    return result;
}
Also used : Driver(org.h2.Driver) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 9 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project sharding-jdbc by dangdangdotcom.

the class AbstractDBUnitTest method createDataSource.

private DataSource createDataSource(final String dataSetFile) {
    if (DATA_SOURCES.containsKey(dataSetFile)) {
        return DATA_SOURCES.get(dataSetFile);
    }
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(dbEnv.getDriverClassName());
    result.setUrl(dbEnv.getURL(getFileName(dataSetFile)));
    result.setUsername(dbEnv.getUsername());
    result.setPassword(dbEnv.getPassword());
    result.setMaxActive(1000);
    DATA_SOURCES.put(dataSetFile, result);
    return result;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 10 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project elastic-job by dangdangdotcom.

the class JavaMain method setUpEventTraceDataSource.

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;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Aggregations

BasicDataSource (org.apache.commons.dbcp.BasicDataSource)141 Connection (java.sql.Connection)25 Test (org.junit.Test)13 SQLException (java.sql.SQLException)12 Properties (java.util.Properties)12 DataSource (javax.sql.DataSource)10 Platform (org.apache.ddlutils.Platform)8 Database (org.apache.ddlutils.model.Database)8 DdlGenerator (siena.jdbc.ddl.DdlGenerator)8 Statement (java.sql.Statement)7 Bean (org.springframework.context.annotation.Bean)6 ResultSet (java.sql.ResultSet)5 Before (org.junit.Before)5 JdbcPersistenceManager (siena.jdbc.JdbcPersistenceManager)5 Config (com.typesafe.config.Config)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Test (org.testng.annotations.Test)3 PostgresqlPersistenceManager (siena.jdbc.PostgresqlPersistenceManager)3