Search in sources :

Example 16 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_addBatch.

public void test_addBatch() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.addBatch("select 1");
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.addBatch("select 1");
        } 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 17 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_clearBatch.

public void test_clearBatch() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.clearBatch();
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.clearBatch();
        } 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 18 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_getMaxFieldSize.

public void test_getMaxFieldSize() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.setMaxFieldSize(23);
    Assert.assertEquals(23, stmt.getMaxFieldSize());
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.getMaxFieldSize();
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    {
        SQLException error = null;
        try {
            stmt.setMaxFieldSize(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 19 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_getResultSetType.

public void test_getResultSetType() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.getResultSetType();
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.getResultSetType();
        } 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 20 with DruidPooledStatement

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

the class DruidPooledStatementTest method test_closeOnCompletion_error.

public void test_closeOnCompletion_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.closeOnCompletion();
    } 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)

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