use of org.apache.commons.dbcp.BasicDataSource in project herddb by diennea.
the class CommonsDBCPTest method test.
@Test
public void test() throws Exception {
try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
server.start();
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl("jdbc:herddb:server:localhost:7000?");
dataSource.setDriverClassName(Driver.class.getName());
try (Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
int count = 0;
while (rs.next()) {
System.out.println("table: " + rs.getString(1));
count++;
}
assertTrue(count > 0);
}
dataSource.close();
}
}
use of org.apache.commons.dbcp.BasicDataSource in project airavata by apache.
the class DBUtil method getDataSource.
/**
* Gets a new DBCP data source.
*
* @return A new data source.
*/
public DataSource getDataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(this.driverName);
ds.setUsername(this.databaseUserName);
ds.setPassword(this.databasePassword);
ds.setUrl(this.jdbcUrl);
return ds;
}
use of org.apache.commons.dbcp.BasicDataSource in project SimpleDAO by justinjmiller.
the class SimpleDBConnection method getPooledDBConnection.
private Connection getPooledDBConnection() throws SQLException {
if (log.isDebugEnabled()) {
log.debug("get a pooled database connection");
}
BasicDataSource ds = new BasicDataSource();
ds.setUrl(databaseURL);
ds.setUsername(databaseUser);
ds.setPassword(databasePassword);
ds.setInitialSize(10);
ds.setMaxIdle(5);
ds.setDriverClassName(databaseDriver);
return ds.getConnection();
}
use of org.apache.commons.dbcp.BasicDataSource in project unipop by unipop-graph.
the class ContextManager method reloadContexts.
private void reloadContexts() throws IOException {
SQLDialect dialect = SQLDialect.valueOf(this.conf.getString("sqlDialect"));
BasicDataSource ds = new BasicDataSource();
ds.setUrl(new ObjectMapper().readValue(conf.getJSONArray("address").toString(), List.class).get(0).toString());
ds.setDriverClassName(conf.getString("driver"));
String user = conf.optString("user");
String password = conf.optString("password");
if (!user.isEmpty())
ds.setUsername(user);
if (!password.isEmpty())
ds.setPassword(password);
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);
Configuration conf = new DefaultConfiguration().set(ds).set(dialect).set(settings).set(new DefaultExecuteListenerProvider(new TimingExecuterListener()));
this.context = DSL.using(conf);
}
use of org.apache.commons.dbcp.BasicDataSource in project ff4j by ff4j.
the class JdbcTestHelper method createInMemoryHQLDataSource.
/**
* Initialize DataSource with a pool of connections to HQL database.
*
* @return
* current data source
*/
public static DataSource createInMemoryHQLDataSource() {
// Init DataSource
BasicDataSource dbcpDataSource = new BasicDataSource();
dbcpDataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dbcpDataSource.setUsername("sa");
dbcpDataSource.setPassword("");
dbcpDataSource.setUrl("jdbc:hsqldb:mem:.");
dbcpDataSource.setMaxActive(3);
dbcpDataSource.setMaxIdle(2);
dbcpDataSource.setInitialSize(2);
dbcpDataSource.setValidationQuery("select 1 from INFORMATION_SCHEMA.SYSTEM_USERS;");
dbcpDataSource.setPoolPreparedStatements(true);
return dbcpDataSource;
}
Aggregations