Search in sources :

Example 36 with DruidDataSource

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

the class DruidConnectionHolderTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    driver = new Driver();
    if (driver.getMajorVersion() == 5) {
        exceptionClass = Class.forName("com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException");
        dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mock:xxx");
        dataSource.setTestOnBorrow(false);
        dataSource.setInitialSize(1);
        dataSource.getProxyFilters().add(new FilterAdapter() {

            public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
                throw createSyntaxException();
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) Driver(com.mysql.jdbc.Driver) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 37 with DruidDataSource

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

the class DruidConnectionHolderTest3 method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setInitialSize(1);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        public int connection_getTransactionIsolation(FilterChain chain, ConnectionProxy connection) throws SQLException {
            throw new MySQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy)

Example 38 with DruidDataSource

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

the class DruidDataSourceDecryptTest method testDecrypt.

@Test
public void testDecrypt() throws SQLException {
    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:oracle:thin:@");
    dataSource.setUsername("xiaoyu");
    dataSource.setPassword("OJfUm6WCHi7EuXqE6aEc+Po2xFrAGBeSNy8O2jWhV2FTG8/5kbRRr2rjNKhptlevm/03Y0048P7h88gdUOXAYg==");
    dataSource.setFilters("config");
    dataSource.setConnectionProperties("config.decrypt=true");
    try {
        dataSource.init();
        Assert.assertEquals("The password is " + dataSource.getPassword(), "xiaoyu", dataSource.getPassword());
    } finally {
        JdbcUtils.close(dataSource);
    }
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource) Test(org.junit.Test)

Example 39 with DruidDataSource

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

the class Bug_for_dupCloseStmtError method tearDown.

protected void tearDown() throws Exception {
    dataSource.close();
    for (DruidDataSource dataSource : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
        JdbcUtils.close(dataSource);
    }
    super.tearDown();
}
Also used : DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Example 40 with DruidDataSource

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

the class Bug_for_dupCloseStmtError method setUp.

protected void setUp() throws Exception {
    super.setUp();
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:");
    dataSource.setPoolPreparedStatements(false);
    dataSource.setTestOnBorrow(true);
}
Also used : 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