Search in sources :

Example 21 with DruidPooledStatement

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

the class ResultSetTest2 method setUp.

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

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
    raw = new MockResultSet(null);
    raw.getRows().add(new Object[] { null });
    resultSet = new DruidPooledResultSet(stmt, raw);
}
Also used : DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet) DruidPooledResultSet(com.alibaba.druid.pool.DruidPooledResultSet)

Example 22 with DruidPooledStatement

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

the class PoolableStatementTest3 method test_clearResultSetError.

public void test_clearResultSetError() throws Exception {
    final MockResultSet rs = new MockResultSet(null) {

        public void close() throws SQLException {
            throw new SQLException();
        }
    };
    DruidPooledStatement stmt = new DruidPooledStatement(null, null) {

        public void close() throws SQLException {
            addResultSetTrace(rs);
            clearResultSet();
        }
    };
    stmt.close();
}
Also used : DruidPooledStatement(com.alibaba.druid.pool.DruidPooledStatement) SQLException(java.sql.SQLException) MockResultSet(com.alibaba.druid.mock.MockResultSet)

Example 23 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_execute_2.

public void test_execute_2() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    stmt.execute("SELECT 1", Statement.NO_GENERATED_KEYS);
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.execute("SELECT 1", Statement.NO_GENERATED_KEYS);
        } 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 24 with DruidPooledStatement

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

the class PoolableStatementTest2 method test_QueryTimeout.

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

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

the class PoolableStatementTest2 method test_execute_error.

public void test_execute_error() throws Exception {
    Connection conn = dataSource.getConnection();
    Statement stmt = conn.createStatement();
    ((DruidPooledStatement) stmt).getStatement().close();
    {
        SQLException error = null;
        try {
            stmt.execute("SET @VAR = 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)

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