apache/shardingsphere · error · SQLFeatureNotSupportedException

afterLast

Error message

afterLast

What it means

afterLast(), which moves the cursor past the final row, is unsupported and final in ShardingSphere's AbstractUnsupportedOperationResultSet — it throws SQLFeatureNotSupportedException. Positioning calls that are not forward next() have no meaning on a streaming merge of shard results, so the driver rejects them.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java:65

    
    @Override
    public final boolean isFirst() throws SQLException {
        throw new SQLFeatureNotSupportedException("isFirst");
    }
    
    @Override
    public final boolean isLast() throws SQLException {
        throw new SQLFeatureNotSupportedException("isLast");
    }
    
    @Override
    public final void beforeFirst() throws SQLException {
        throw new SQLFeatureNotSupportedException("beforeFirst");
    }
    
    @Override
    public final void afterLast() throws SQLException {
        throw new SQLFeatureNotSupportedException("afterLast");
    }
    
    @Override
    public final boolean first() throws SQLException {
        throw new SQLFeatureNotSupportedException("first");
    }
    
    @Override
    public final boolean last() throws SQLException {
        throw new SQLFeatureNotSupportedException("last");
    }
    
    @Override
    public final boolean absolute(final int row) throws SQLException {
        throw new SQLFeatureNotSupportedException("absolute");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. To skip remaining rows, simply close() the ResultSet (and Statement) — closing discards the streams safely.
  2. If exhaustion is required, while (rs.next()) { } is the only supported way to advance to the end.
  3. Remove the call: for forward-only cursors, afterLast() has no useful effect.
  4. Wrap consumers that insist on afterLast() with a materialized CachedRowSet.

Example fix

// before
rs.afterLast(); // throws
rs.close();

// after
rs.close(); // forward-only: closing is sufficient to discard remaining rows
Defensive patterns

Strategy: validation

Validate before calling

if (rs.getType() == ResultSet.TYPE_FORWARD_ONLY) {
    // positioning calls other than next() are unavailable; just close() to discard
}

Try / catch

try {
    rs.afterLast();
} catch (SQLFeatureNotSupportedException e) {
    rs.close(); // equivalent effect for a forward-only cursor
}

Prevention

When it happens

Trigger: Calling rs.afterLast() on a ShardingSphere query result, usually in generic cleanup/skip-resteps code or copy-pasted scrollable-cursor examples.

Common situations: Defensive 'drain the rest' code before closing; frameworks that normalize cursor state via afterLast(); migrations from drivers whose result sets allow repositioning.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/55c589ca11a3b76b. Report an issue: GitHub.