apache/shardingsphere · error · SQLFeatureNotSupportedException

getUnicodeStream

Error message

getUnicodeStream

What it means

GeneratedKeysResultSet, the ResultSet ShardingSphere's driver returns from getGeneratedKeys(), inherits getUnicodeStream(int) from AbstractUnsupportedGeneratedKeysResultSet as an unconditional throw of SQLFeatureNotSupportedException("getUnicodeStream"). getUnicodeStream is itself a deprecated JDBC 1.0 method, and since generated keys are synthesized scalar values there is no unicode character stream to return.

Source

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

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

View on GitHub (pinned to e952770a21)

Solutions

  1. Replace with getLong(1)/getObject(1) — getUnicodeStream has been deprecated since JDBC 2.0 and even on native drivers is discouraged.
  2. If character data is genuinely expected, you are using the wrong result set: generated keys only ever contain the key column.
  3. Catch SQLFeatureNotSupportedException around legacy library calls and re-fetch the key with a typed getter or a follow-up query.
  4. Remove dead getUnicodeStream branches from generic mappers; no current driver guarantees them.

Example fix

// before
InputStream raw = keys.getUnicodeStream(1);

// after
long id = keys.getLong(1);
Defensive patterns

Strategy: try-catch

Validate before calling

if (keys.getMetaData().getColumnCount() == 1) {
    long id = keys.getLong(1);
}

Type guard

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

Try / catch

try {
    InputStream in = rs.getUnicodeStream(1);
} catch (SQLFeatureNotSupportedException e) {
    Object v = rs.getObject(1); // safe fallback
}

Prevention

When it happens

Trigger: Calling resultSet.getUnicodeStream(int columnIndex) on the ResultSet returned by Statement.getGeneratedKeys() or PreparedStatement.getGeneratedKeys() in the ShardingSphere driver (line 132 covers the columnIndex overload).

Common situations: Very old JDBC code or code translated from JDK 1.1-era samples still using getUnicodeStream; automated result-set-to-POJO mappers that enumerate every accessor; apps moved onto ShardingSphere-JDBC for sharding where the native driver previously returned a (possibly empty) stream.

Related errors


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