apache/shardingsphere · error · SQLFeatureNotSupportedException
getCharacterStream
Error message
getCharacterStream
What it means
The int-overload getCharacterStream(int columnIndex) throws SQLFeatureNotSupportedException("getCharacterStream") unconditionally in AbstractUnsupportedGeneratedKeysResultSet:162, so it fails on the ResultSet ShardingSphere returns from getGeneratedKeys(). The generated-keys result set contains a single numeric column assembled in memory; Reader-based column access is not part of its contract.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java:162
@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
public final int getFetchDirection() throws SQLException {
throw new SQLFeatureNotSupportedException("getFetchDirection");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Read the key with getLong(1)/getBigDecimal(1)/getObject(1); convert to String in Java if character data is needed.
- In generic mappers, use getObject(1) and format via toString() rather than branching into Reader accessors.
- Do not run row-serialization logic against getGeneratedKeys() output; serialize the entity you already have in memory.
- For third-party mappers you cannot patch, catch SQLFeatureNotSupportedException and fall back to getString(1).
Example fix
// before Reader r = keys.getCharacterStream(1); // after String id = keys.getString(1); // or keys.getLong(1)
Defensive patterns
Strategy: try-catch
Validate before calling
int type = keys.getMetaData().getColumnType(1);
if (type == Types.INTEGER || type == Types.BIGINT) {
long id = keys.getLong(1); // never use Reader accessors here
} Type guard
private static boolean isGeneratedKeysRs(ResultSet rs) {
return rs.getClass().getName().endsWith("GeneratedKeysResultSet");
} Try / catch
try {
Reader r = rs.getCharacterStream(1);
} catch (SQLFeatureNotSupportedException e) {
String v = rs.getString(1);
} Prevention
- Serialize entities from your own objects after INSERT; don't dump key result sets.
- Default generic mappers to getObject().
- Reserve Reader accessors for verified text columns in query result sets.
When it happens
Trigger: Calling resultSet.getCharacterStream(1) on the keys ResultSet — typical of generic row mappers (Hibernate legacy type handlers, Jackson/CSV serializers) that choose getCharacterStream for CHAR/VARCHAR/LONGVARCHAR metadata types.
Common situations: Generic ORM serialization of 'whatever result set is open' after an INSERT; utility code that dumps any ResultSet to JSON/CSV; apps whose native driver returned a Reader over the key's string form and only broke once ShardingSphere-JDBC took over statement routing.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/3b0a2fa7be0bb138.
Report an issue: GitHub.