Search in sources :

Example 1 with JdbcRowBaseIterator

use of io.mycat.beans.mycat.JdbcRowBaseIterator in project Mycat2 by MyCATApache.

the class DefaultConnection method executeQuery.

public RowBaseIterator executeQuery(String sql) {
    try {
        Statement statement = connection.createStatement();
        statement.setFetchSize(1);
        ResultSet resultSet = statement.executeQuery(sql);
        return new JdbcRowBaseIterator(null, this, statement, resultSet, new RowIteratorCloseCallback() {

            @Override
            public void onClose(long rowCount) {
            }
        }, sql);
    } catch (Exception e) {
        throw new MycatException(e);
    }
}
Also used : JdbcRowBaseIterator(io.mycat.beans.mycat.JdbcRowBaseIterator) MycatException(io.mycat.MycatException) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) MycatException(io.mycat.MycatException) SQLException(java.sql.SQLException)

Example 2 with JdbcRowBaseIterator

use of io.mycat.beans.mycat.JdbcRowBaseIterator in project Mycat2 by MyCATApache.

the class MycatPreparedStatementUtil method executeQuery.

@SneakyThrows
public static RowBaseIterator executeQuery(Connection mycatConnection, MycatConnection connection, MycatRowMetaData calciteRowMetaData, SqlString value, List<Object> params, RowIteratorCloseCallback closeCallback) {
    String sql = value.getSql();
    try {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("sql:{} {}", sql, (params).toString());
        }
        PreparedStatement preparedStatement = mycatConnection.prepareStatement(sql);
        ImmutableList<Integer> dynamicParameters = value.getDynamicParameters();
        List<Object> outoutParams = extractParams(params, dynamicParameters);
        MycatPreparedStatementUtil.setParams(preparedStatement, outoutParams);
        ResultSet resultSet = preparedStatement.executeQuery();
        return new JdbcRowBaseIterator(calciteRowMetaData, connection, preparedStatement, resultSet, closeCallback, sql);
    } catch (Throwable throwable) {
        LOGGER.error("sql:{} {}", sql, (params).toString(), throwable);
        throw throwable;
    }
}
Also used : JdbcRowBaseIterator(io.mycat.beans.mycat.JdbcRowBaseIterator) SqlString(org.apache.calcite.sql.util.SqlString) SneakyThrows(lombok.SneakyThrows)

Aggregations

JdbcRowBaseIterator (io.mycat.beans.mycat.JdbcRowBaseIterator)2 MycatException (io.mycat.MycatException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 SneakyThrows (lombok.SneakyThrows)1 SqlString (org.apache.calcite.sql.util.SqlString)1