Search in sources :

Example 36 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project ma-core-public by infiniteautomation.

the class BasePooledProxy method initializeImpl.

@Override
protected void initializeImpl(String propertyPrefix) {
    log.info("Initializing pooled connection manager");
    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(getDriverClassName());
    dataSource.setUrl(getUrl(propertyPrefix));
    dataSource.setUsername(Common.envProps.getString(propertyPrefix + "db.username"));
    dataSource.setPassword(getDatabasePassword(propertyPrefix));
    dataSource.setMaxActive(Common.envProps.getInt(propertyPrefix + "db.pool.maxActive", 10));
    dataSource.setMaxIdle(Common.envProps.getInt(propertyPrefix + "db.pool.maxIdle", 10));
    dataSource.setValidationQuery("SELECT 1");
    dataSource.setTestOnBorrow(true);
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 37 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project citrus-samples by christophd.

the class EndpointConfig method todoListDataSource.

@Bean(destroyMethod = "close")
public BasicDataSource todoListDataSource() {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    dataSource.setUrl("jdbc:hsqldb:hsql://localhost/testdb");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    dataSource.setInitialSize(1);
    dataSource.setMaxActive(5);
    dataSource.setMaxIdle(2);
    return dataSource;
}
Also used : BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Bean(org.springframework.context.annotation.Bean)

Example 38 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project notes by KevinBlandy.

the class Demo method method1.

public static void method1() throws SQLException {
    /**
     * �������ӳض���,�����Ĵ����
     * ���óز���
     * �õ����Ӷ���
     */
    // �������ӳض���
    BasicDataSource dataSource = new BasicDataSource();
    // �����Ĵ����
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/demo");
    dataSource.setUsername("root");
    dataSource.setPassword("root");
    // �������������
    dataSource.setMaxActive(20);
    // ������С�Ŀ�������
    dataSource.setMinIdle(3);
    // �������ȴ�ʱ��
    dataSource.setMaxWait(1000);
    // �õ����ӳض���
    Connection conn = dataSource.getConnection();
    System.out.println(conn.getClass().getName());
}
Also used : Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource)

Example 39 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project nutz by nutzam.

the class PsTest method main.

/**
 * 测试新的Dao实现在postgresql下的表现
 */
public static void main(String[] args) throws Throwable {
    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("org.postgresql.Driver");
    ds.setUsername("postgres");
    ds.setPassword("123456");
    ds.setUrl("jdbc:postgresql:test");
    ds.setDefaultAutoCommit(false);
    final NutDao dao = new NutDao(ds);
    TableName.run(1, new Atom() {

        public void run() {
            Trans.exec(new Atom() {

                public void run() {
                    dao.create(Country.class, true);
                    System.out.println("------------???");
                    dao.insert(Country.make("A"));
                    try {
                        System.out.println("---------------------");
                        dao.insert(Country.make("A"));
                        System.out.println("+++++++++++++++++++++++++++++++++++");
                    } catch (DaoException e) {
                    }
                    try {
                        dao.insert(Country.make("C"));
                    } catch (Throwable e) {
                        System.out.println("天啊,还是报错!!");
                    }
                }
            });
        }
    });
    Connection conn = ds.getConnection();
    conn.prepareStatement("insert into dao_country(name,detail) values('ABC','CC')").execute();
    try {
        conn.prepareStatement("insert into dao_country(name,detail) values('ABC','CC')").execute();
    } catch (Exception e) {
    }
    conn.prepareStatement("insert into dao_country(name,detail) values('CC','CC')").execute();
    System.out.println("竟然能通过??!!");
    conn.commit();
}
Also used : NutDao(org.nutz.dao.impl.NutDao) Connection(java.sql.Connection) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Atom(org.nutz.trans.Atom)

Example 40 with BasicDataSource

use of org.apache.commons.dbcp.BasicDataSource in project qi4j-sdk by Qi4j.

the class ExternalDataSourceTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    BasicDataSource externalDataSource = new BasicDataSource();
    externalDataSource.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver");
    externalDataSource.setUrl("jdbc:derby:memory:testdbexternal;create=true");
    // START SNIPPET: assembly
    new ExternalDataSourceAssembler(externalDataSource).visibleIn(Visibility.module).identifiedBy("datasource-external-id").withCircuitBreaker(DataSources.newDataSourceCircuitBreaker()).assemble(module);
// END SNIPPET: assembly
}
Also used : ExternalDataSourceAssembler(org.qi4j.library.sql.assembly.ExternalDataSourceAssembler) 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