Example usage for java.sql CallableStatement setFetchDirection

List of usage examples for java.sql CallableStatement setFetchDirection

Introduction

In this page you can find the example usage for java.sql CallableStatement setFetchDirection.

Prototype

void setFetchDirection(int direction) throws SQLException;

Source Link

Document

Gives the driver a hint as to the direction in which rows will be processed in ResultSet objects created using this Statement object.

Usage

From source file:org.apache.openjpa.jdbc.sql.SQLBuffer.java

/**
 * Create and populate the parameters of a prepred statement using the
 * SQL in this buffer and the given fetch configuration.
 *///from w w  w  . j  av a2  s. co  m
public CallableStatement prepareCall(Connection conn, JDBCFetchConfiguration fetch, int rsType, int rsConcur)
        throws SQLException {
    if (rsType == -1 && fetch == null)
        rsType = ResultSet.TYPE_FORWARD_ONLY;
    else if (rsType == -1)
        rsType = fetch.getResultSetType();
    if (rsConcur == -1)
        rsConcur = ResultSet.CONCUR_READ_ONLY;

    CallableStatement stmnt;
    if (rsType == ResultSet.TYPE_FORWARD_ONLY && rsConcur == ResultSet.CONCUR_READ_ONLY)
        stmnt = conn.prepareCall(getSQL());
    else
        stmnt = conn.prepareCall(getSQL(), rsType, rsConcur);
    try {
        setParameters(stmnt);
        if (fetch != null) {
            if (fetch.getFetchBatchSize() > 0)
                stmnt.setFetchSize(_dict.getBatchFetchSize(fetch.getFetchBatchSize()));
            if (rsType != ResultSet.TYPE_FORWARD_ONLY && fetch.getFetchDirection() != ResultSet.FETCH_FORWARD)
                stmnt.setFetchDirection(fetch.getFetchDirection());
        }
        return stmnt;
    } catch (SQLException se) {
        try {
            stmnt.close();
        } catch (SQLException se2) {
        }
        throw se;
    }
}