public T query()

in src/main/java/org/apache/commons/dbutils/QueryRunner.java [584:622]


    public <T> T query(final Connection conn, final String sql, final ResultSetHandler<T> rsh, final Object... params) throws SQLException {
        if (conn == null) {
            throw new SQLException("Null connection");
        }

        if (sql == null) {
            throw new SQLException("Null SQL statement");
        }

        if (rsh == null) {
            throw new SQLException("Null ResultSetHandler");
        }

        Statement stmt = null;
        ResultSet resultSet = null;
        T result = null;

        try {
            if (params != null && params.length > 0) {
                final PreparedStatement ps = this.prepareStatement(conn, sql);
                stmt = ps;
                this.fillStatement(ps, params);
                resultSet = wrap(ps.executeQuery());
            } else {
                stmt = conn.createStatement();
                resultSet = wrap(stmt.executeQuery(sql));
            }
            result = rsh.handle(resultSet);

        } catch (final SQLException e) {
            rethrow(e, sql, params);

        } finally {
            closeQuietly(resultSet);
            closeQuietly(stmt);
        }

        return result;
    }