apache/shardingsphere · error · SQLFeatureNotSupportedException

clearWarnings

Error message

clearWarnings

What it means

clearWarnings() on ShardingSphere's generated-keys ResultSet always throws SQLFeatureNotSupportedException("clearWarnings") (AbstractUnsupportedGeneratedKeysResultSet:157). Because the synthesized key result set neither stores nor tracks warnings, clearing them is defined as unsupported, mirroring getWarnings() on the line above.

Source

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

    
    @Override
    public final InputStream getBinaryStream(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getBinaryStream");
    }
    
    @Override
    public final InputStream getBinaryStream(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getBinaryStream");
    }
    
    @Override
    public final SQLWarning getWarnings() throws SQLException {
        throw new SQLFeatureNotSupportedException("getWarnings");
    }
    
    @Override
    public final void clearWarnings() throws SQLException {
        throw new SQLFeatureNotSupportedException("clearWarnings");
    }
    
    @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

View on GitHub (pinned to e952770a21)

Solutions

  1. Remove clearWarnings() from cleanup paths for generated-keys result sets; it is a no-op semantically there anyway.
  2. Wrap the call in try-catch (SQLFeatureNotSupportedException) inside generic hygiene helpers and ignore it for this result set type.
  3. Call clearWarnings() on the Statement or Connection instead, where it is supported.
  4. If you maintain a JDBC wrapper library, feature-detect with a single probe call and cache the capability per result-set class.

Example fix

// before
rs.clearWarnings();

// after
try {
    rs.clearWarnings();
} catch (SQLFeatureNotSupportedException ignore) {
    // generated-keys result set tracks no warnings
}
Defensive patterns

Strategy: try-catch

Validate before calling

// only clear warnings on result sets known to support them (not generated-keys ones)
if (!keys.getClass().getName().endsWith("GeneratedKeysResultSet")) {
    keys.clearWarnings();
}

Type guard

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

Try / catch

try {
    rs.clearWarnings();
} catch (SQLFeatureNotSupportedException ignore) {
    // no warning state exists on this result set
}

Prevention

When it happens

Trigger: Calling resultSet.clearWarnings() on the result of Statement.getGeneratedKeys()/PreparedStatement.getGeneratedKeys() — frequently executed by pooled-connection reset logic, ORM session flushes, or generic 'cleanup result set' helpers that clear warnings after processing.

Common situations: Connection pools and transaction managers that reset warning state on every statement/result set they recycle; frameworks with a finally-block hygiene routine calling clearWarnings(); the failure appearing only after introducing ShardingSphere-JDBC into a stack that previously used a plain driver.

Related errors


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