Search in sources :

Example 1 with DruidPooledStatement

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

the class DruidPooledStatementTest method test_isCloseOnCompletion_error.

public void test_isCloseOnCompletion_error() throws Exception {
    Connection conn = dataSource.getConnection();
    DruidPooledStatement stmt = (DruidPooledStatement) conn.createStatement();
    Assert.assertEquals(0, dataSource.getPoolingCount());
    Assert.assertEquals(1, dataSource.getActiveCount());
    Assert.assertEquals(0, dataSource.getErrorCount());
    Exception error = null;
    try {
        stmt.isCloseOnCompletion();
    } catch (SQLFeatureNotSupportedException e) {
        error = e;
    }
    Assert.assertNotNull(error);
    Assert.assertEquals(0, dataSource.getErrorCount());
    stmt.close();
    conn.close();
    Assert.assertEquals(1, dataSource.getPoolingCount());
    Assert.assertEquals(0, dataSource.getActiveCount());
}
Also used : DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) Connection(java.sql.Connection) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException)

Example 2 with DruidPooledStatement

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

the class PoolableStatementTest method setUp.

protected void setUp() throws Exception {
    raw = new MockStatement(null);
    stmt = new DruidPooledStatement(null, raw) {

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
}
Also used : DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) SQLException(java.sql.SQLException) MockStatement(com.alibaba.druid.mock.MockStatement)

Example 3 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_FetchSize.

public void test_FetchSize() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.setFetchSize(144);
    Assert.assertEquals(144, stmt.getFetchSize());
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.getFetchSize();
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    {
        SQLException error = null;
        try {
            stmt.setFetchSize(23);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    stmt.close();
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection)

Example 4 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_FetchDirection.

public void test_FetchDirection() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.setFetchDirection(144);
    Assert.assertEquals(144, stmt.getFetchDirection());
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.getFetchDirection();
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    {
        SQLException error = null;
        try {
            stmt.setFetchDirection(23);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    stmt.close();
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection)

Example 5 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_setEscapeProcessing.

public void test_setEscapeProcessing() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.setEscapeProcessing(true);
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.setEscapeProcessing(true);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    stmt.close();
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection)

Aggregations

DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)39 SQLException (java.sql.SQLException)39 Connection (java.sql.Connection)35 CallableStatement (java.sql.CallableStatement)33 PreparedStatement (java.sql.PreparedStatement)33 Statement (java.sql.Statement)33 MockResultSet (com.alibaba.druid.mock.MockResultSet)3 DruidPooledResultSet (com.alibaba.druid.pool.DruidPooledResultSet)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)2 MockStatement (com.alibaba.druid.mock.MockStatement)1