apache/shardingsphere · error · SQLFeatureNotSupportedException

getWarnings

Error message

getWarnings

What it means

ShardingSphere's GeneratedKeysResultSet (returned by getGeneratedKeys()) inherits getWarnings() as an unconditional SQLFeatureNotSupportedException("getWarnings") throw (AbstractUnsupportedGeneratedKeysResultSet:152). The synthesized key result set never accumulates SQLWarnings, so the warning chain API is closed off rather than returning null.

Source

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

    
    @Override
    public final InputStream getUnicodeStream(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getUnicodeStream");
    }
    
    @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

View on GitHub (pinned to e952770a21)

Solutions

  1. Guard the call: skip getWarnings() when the result set came from getGeneratedKeys() (check rs.getMetaData().getColumnCount() == 1 and the statement context, or simply don't warn-scan key result sets).
  2. Catch SQLFeatureNotSupportedException and treat it as 'no warnings' if you cannot change the call site.
  3. In wrappers/agents, feature-detect once with a cheap probe and remember that this result set class does not support warnings.
  4. Retrieve warnings from the Statement/Connection level instead if warning collection matters to you.

Example fix

// before
SQLWarning w = rs.getWarnings();

// after
SQLWarning w;
try {
    w = rs.getWarnings();
} catch (SQLFeatureNotSupportedException e) {
    w = null; // generated-keys result set does not support warnings
}
Defensive patterns

Strategy: try-catch

Validate before calling

// getMetaData() is supported: use it to detect the single-column key result set before warning scans
if (keys.getMetaData().getColumnCount() > 1) {
    SQLWarning w = keys.getWarnings();
}

Type guard

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

Try / catch

SQLWarning w = null;
try {
    w = rs.getWarnings();
} catch (SQLFeatureNotSupportedException e) {
    // treat as no warnings
}

Prevention

When it happens

Trigger: Calling resultSet.getWarnings() on the ResultSet from Statement.getGeneratedKeys() or PreparedStatement.getGeneratedKeys() — commonly inside strict JDBC compliance wrappers, monitoring agents (e.g. P6Spy-style interceptors), or code that drains warnings after each row batch.

Common situations: JDBC monitoring/proxy layers and connection pools that call getWarnings() on every result set they manage; frameworks doing strict warning scans (some test harnesses assert null warnings); apps that previously used a native driver where getWarnings() returned null on generated keys and only failed after moving to ShardingSphere-JDBC.

Related errors


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