Search in sources :

Example 21 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class Case_Concurrent_50 method test_0.

public void test_0() throws Exception {
    final DruidDataSource dataSource = new DruidDataSource();
    dataSource.setInitialSize(initialSize);
    dataSource.setMaxActive(maxActive);
    dataSource.setMinIdle(minIdle);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxWait(6000);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    for (int i = 0; i < LOOP_COUNT; ++i) {
        p0(dataSource, "druid");
    }
    System.out.println();
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 22 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class Oracle_Case3 method test_0.

public void test_0() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setMaxActive(maxActive);
    dataSource.setMaxIdle(maxIdle);
    dataSource.setMaxWait(maxWait);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);
    dataSource.setTestOnBorrow(testOnBorrow);
    for (int i = 0; i < loopCount; ++i) {
        p0(dataSource, "druid", threadCount);
    }
    System.out.println();
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 23 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class TestRollBack method init.

// jdbcUrl = "jdbc:oracle:thin:@a.b.c.d:1521:ocnauto";
// user = "alibaba";
// password = "ccbuauto";
@BeforeClass
public static void init() throws PropertyVetoException, SQLException {
    c3p0 = new ComboPooledDataSource();
    // c3p0.setDriverClass("oracle.jdbc.driver.OracleDriver");
    c3p0.setDriverClass(driver);
    c3p0.setJdbcUrl(url);
    c3p0.setUser(user);
    c3p0.setPassword(password);
    druid = new DruidDataSource();
    druid.setUrl(url);
    druid.setUsername(user);
    druid.setPassword(password);
    druid.setFilters("stat,trace,encoding");
    druid.setDefaultAutoCommit(false);
    dao_c3p0 = new NutDao(c3p0);
    dao_druid = new NutDao(druid);
    if (!dao_c3p0.exists("msg")) {
        // 字段长度5
        dao_c3p0.execute(Sqls.create("create table msg(message varchar(5))"));
    }
}
Also used : ComboPooledDataSource(com.mchange.v2.c3p0.ComboPooledDataSource) NutDao(org.nutz.dao.impl.NutDao) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) BeforeClass(org.junit.BeforeClass)

Example 24 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class TestTraceFilter method test_loop.

public void test_loop() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setFilters("stat,trace");
    dataSource.setUrl("jdbc:mock:");
    JMXUtils.register("com.alibaba.dragoon:type=JdbcTraceManager", JdbcTraceManager.getInstance());
    for (int i = 0; i < 1000; ++i) {
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT 1");
        rs.next();
        rs.close();
        stmt.close();
        conn.close();
        Thread.sleep(1000);
    }
    dataSource.close();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 25 with DruidDataSource

use of com.alibaba.druid.pool.DruidDataSource in project druid by alibaba.

the class TestOracle method test_o.

public void test_o() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setDriverClassName(driverClass);
    dataSource.setUrl(jdbcUrl);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setMaxOpenPreparedStatements(50);
    dataSource.setUseOracleImplicitCache(true);
    for (int i = 1; i <= 1; ++i) {
        Connection conn = dataSource.getConnection();
        // (i % 50) + 1;
        int rowNum = i + 1;
        String sql = SQL + " AND ROWNUM <= " + rowNum;
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt.setInt(1, 61);
        ResultSet rs = stmt.executeQuery();
        int rowCount = 0;
        while (rs.next()) {
            rowCount++;
        }
        Assert.assertEquals(true, rowCount > 0);
        // Assert.isTrue(!rs.isClosed());
        rs.close();
        // Assert.isTrue(!stmt.isClosed());
        stmt.close();
        conn.close();
    }
    dataSource.close();
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

DruidDataSource (com.alibaba.druid.pool.DruidDataSource)474 SQLException (java.sql.SQLException)74 OracleMockDriver (com.alibaba.druid.test.util.OracleMockDriver)56 OracleExceptionSorter (com.alibaba.druid.pool.vendor.OracleExceptionSorter)50 MockDriver (com.alibaba.druid.mock.MockDriver)49 Connection (java.sql.Connection)43 Properties (java.util.Properties)41 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)35 FilterChain (com.alibaba.druid.filter.FilterChain)33 Bean (org.springframework.context.annotation.Bean)21 ResultSet (java.sql.ResultSet)20 Test (org.junit.Test)19 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)18 PreparedStatement (java.sql.PreparedStatement)14 Primary (org.springframework.context.annotation.Primary)14 MockConnection (com.alibaba.druid.mock.MockConnection)13 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)13 Method (java.lang.reflect.Method)11 Map (java.util.Map)11 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10