prestodb/presto · error · SQLException
Fetch direction must be FETCH_FORWARD
Error message
Fetch direction must be FETCH_FORWARD
What it means
setFetchDirection is a validation guard in PrestoResultSet: after checkOpen(), any direction other than ResultSet.FETCH_FORWARD is rejected with this SQLException, because Presto result sets can only be iterated forward.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:701
throws SQLException
{
throw new SQLFeatureNotSupportedException("relative");
}
@Override
public boolean previous()
throws SQLException
{
throw new SQLFeatureNotSupportedException("previous");
}
@Override
public void setFetchDirection(int direction)
throws SQLException
{
checkOpen();
if (direction != FETCH_FORWARD) {
throw new SQLException("Fetch direction must be FETCH_FORWARD");
}
}
@Override
public int getFetchDirection()
throws SQLException
{
checkOpen();
return FETCH_FORWARD;
}
@Override
public void setFetchSize(int rows)
throws SQLException
{
checkOpen();
if (rows < 0) {
throw new SQLException("Rows is negative");View on GitHub (pinned to 55bb57d202)
Solutions
- Pass ResultSet.FETCH_FORWARD explicitly, or do not call setFetchDirection at all
- Set fetch direction only when the code detects a non-Presto JDBC driver
- Guard the call in a try-catch if the setting is purely advisory for your use case
Example fix
// before rs.setFetchDirection(ResultSet.FETCH_UNKNOWN); // after rs.setFetchDirection(ResultSet.FETCH_FORWARD);
Defensive patterns
Strategy: validation
Validate before calling
if (direction != ResultSet.FETCH_FORWARD) {
throw new IllegalArgumentException("Presto supports only FETCH_FORWARD");
}
rs.setFetchDirection(direction); Prevention
- Always pass ResultSet.FETCH_FORWARD or omit the call
- Skip setFetchDirection when the driver is Presto (check conn.getMetaData().getDatabaseProductName())
- Do not apply shared JDBC tuning code blindly to Presto connections
When it happens
Trigger: Calling setFetchDirection(FETCH_REVERSE) or setFetchDirection(FETCH_UNKNOWN) on a PrestoResultSet or its Statement.
Common situations: Generic connection-pool or framework initialization code that sets FETCH_UNKNOWN by default; ported code from drivers that accept any fetch direction.
Related errors
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/1bddaf7cfe75a7fe.
Report an issue: GitHub.