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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations