apache/shardingsphere · error · SQLFeatureNotSupportedException

getFetchDirection

Error message

getFetchDirection

What it means

getFetchDirection() throws SQLFeatureNotSupportedException("getFetchDirection") unconditionally in AbstractUnsupportedGeneratedKeysResultSet:177, which GeneratedKeysResultSet (the getGeneratedKeys() result of ShardingSphere's driver) extends. Since no direction can be set, querying it is likewise closed off instead of returning FETCH_FORWARD.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java:177

    
    @Override
    public final Reader getCharacterStream(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getCharacterStream");
    }
    
    @Override
    public final Reader getCharacterStream(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getCharacterStream");
    }
    
    @Override
    public final void setFetchDirection(final int direction) throws SQLException {
        throw new SQLFeatureNotSupportedException("setFetchDirection");
    }
    
    @Override
    public final int getFetchDirection() throws SQLException {
        throw new SQLFeatureNotSupportedException("getFetchDirection");
    }
    
    @Override
    public final void setFetchSize(final int rows) throws SQLException {
        throw new SQLFeatureNotSupportedException("setFetchSize");
    }
    
    @Override
    public final int getFetchSize() throws SQLException {
        throw new SQLFeatureNotSupportedException("getFetchSize");
    }
    
    @Override
    public final Blob getBlob(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getBlob");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. Remove or skip getFetchDirection() for generated-keys result sets; assume FETCH_FORWARD semantics.
  2. Catch SQLFeatureNotSupportedException and default to ResultSet.FETCH_FORWARD when introspecting generic result sets.
  3. Feature-probe once per result-set class in wrapper libraries and cache the answer.
  4. Keep direction logic on the Statement/normal query ResultSet where it is supported.

Example fix

// before
int dir = rs.getFetchDirection();

// after
int dir;
try {
    dir = rs.getFetchDirection();
} catch (SQLFeatureNotSupportedException e) {
    dir = ResultSet.FETCH_FORWARD;
}
Defensive patterns

Strategy: try-catch

Validate before calling

Object target = stmt.unwrap(org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.class);
// simpler: only introspect fetch direction on query result sets

Type guard

private static boolean supportsFetchHints(ResultSet rs) {
    return !rs.getClass().getName().endsWith("GeneratedKeysResultSet");
}

Try / catch

int dir;
try {
    dir = rs.getFetchDirection();
} catch (SQLFeatureNotSupportedException e) {
    dir = ResultSet.FETCH_FORWARD;
}

Prevention

When it happens

Trigger: Calling resultSet.getFetchDirection() on the keys ResultSet — common in JDBC wrappers, data-access templates, and diagnostic/audit code that records the fetch mode of every result set.

Common situations: Generic data-access layers that branch on fetch direction before iterating; monitoring agents logging result-set configuration; previously-working code against a native driver that returned FETCH_FORWARD, failing after migration to ShardingSphere-JDBC.

Related errors


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