Search in sources :

Example 31 with BasicDataSource

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();
    }
}
Also used : Server(herddb.server.Server) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Test(org.junit.Test)

Example 32 with BasicDataSource

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

Example 33 with BasicDataSource

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

Example 34 with BasicDataSource

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);
}
Also used : DefaultConfiguration(org.jooq.impl.DefaultConfiguration) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) List(java.util.List) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) ObjectMapper(org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper) Settings(org.jooq.conf.Settings)

Example 35 with BasicDataSource

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