apache/shardingsphere · error · SQLFeatureNotSupportedException
clearWarnings
Error message
clearWarnings
What it means
java.sql.SQLFeatureNotSupportedException thrown by the Apache ShardingSphere JDBC driver when ResultSet.clearWarnings() is called on a DatabaseMetaData result set. Metadata calls such as Connection.getMetaData().getTables()/getColumns()/getIndexInfo()/getPrimaryKeys() on a jdbc:shardingsphere: URL return a synthesized DatabaseMetaDataResultSet that buffers every row as plain Java objects, so only scalar getters (getString, getInt, getBytes, single-arg getDate/getTime/getTimestamp, ...) are implemented. clearWarnings() is declared final in AbstractUnsupportedDatabaseMetaDataResultSet and always throws, so this is a permanent, intentional limitation, not a version bug. Because rows are copied into an in-memory iterator, the metadata result set never accumulates warnings and the whole warnings API is stubbed out.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedDatabaseMetaDataResultSet.java:76
@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 Array getArray(final int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException("getArray");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Remove the rs.clearWarnings() call: metadata result sets never produce warnings, so skipping it changes nothing.
- If you cannot remove it (library code), wrap the call in a catch (SQLFeatureNotSupportedException) and ignore.
- If warning handling is genuinely needed for real queries, call getWarnings()/clearWarnings() on ResultSets from Statement.executeQuery, not on DatabaseMetaData result sets.
- Do not wait for a driver upgrade: the throw is final and by design.
Example fix
// before - throws SQLFeatureNotSupportedException on ShardingSphere metadata result sets
SQLWarning w = metaDataRs.getWarnings();
metaDataRs.clearWarnings();
// after - the metadata result set never carries warnings; just remove the calls
// (or guard them when the same loop also runs on other drivers)
try {
metaDataRs.clearWarnings();
} catch (final SQLFeatureNotSupportedException ignored) {
// ShardingSphere metadata result sets do not support warnings
} Defensive patterns
Strategy: try-catch
Validate before calling
// Run BEFORE using exotic getters: detect a ShardingSphere-synthesized metadata ResultSet
static boolean isShardingSphereMetaDataResultSet(final ResultSet rs) {
return rs != null && "org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet"
.equals(rs.getClass().getName());
}
static boolean supportsMetaDataGetter(final Connection c) throws SQLException {
// jdbc:shardingsphere: URLs return the synthesized metadata result set
return c != null && !c.getMetaData().getURL().startsWith("jdbc:shardingsphere:");
} Type guard
private static boolean isUnsupportedMetaDataResultSet(final ResultSet rs) {
return rs != null && rs.getClass().getName().startsWith("org.apache.shardingsphere.driver.jdbc.core.resultset.DatabaseMetaDataResultSet");
} Try / catch
try {
return rs.clearWarnings();
} catch (final SQLFeatureNotSupportedException e) {
// ShardingSphere metadata result sets: fall back to the implemented scalar getter
// nothing to clear - ignore
} Prevention
- Never assume a JDBC driver implements every ResultSet getter; DatabaseMetaData results are the most commonly stubbed surface.
- When adding ShardingSphere in front of an existing datasource, smoke-test the metadata paths your frameworks use (getTables/getColumns loops) before shipping.
- Prefer the simplest getter (getString/getObject/getBytes) and convert in application code; it is portable across drivers.
- Treat SQLFeatureNotSupportedException (an SQLException subclass) as a signal about capability, not a transient failure - never retry it.
- Keep getWarnings()/clearWarnings() calls out of generic metadata loops; many pooling/sharding wrappers do not forward them.
When it happens
Trigger: Calling clearWarnings() on the ResultSet returned by ShardingSphereDatabaseMetaData, e.g. connection.getMetaData().getTables(null, null, "%", new String[]{"TABLE"}") followed by rs.clearWarnings()) where connection was opened with the org.apache.shardingsphere.driver JDBC URL (jdbc:shardingsphere:classpath:sharding.yaml or jdbc:shardingsphere:...). Both the int-columnIndex and String-columnLabel overloads of every listed getter throw; the methods are final so no subclass can override them.
Common situations: Code that ran unchanged against the native MySQL/PostgreSQL/OpenGauss driver and is repointed to the ShardingSphere driver URL, so the same metadata loop now hits the stubbed getter; generic schema tooling that enumerates JDBC metadata with feature-rich getters (DBeaver, Squirrel SQL, Liquibase/Hibernate/Flyway schema validators, code generators, DBDiff tools); hand-written metadata loops that defensively call getWarnings()/clearWarnings() or use the Calendar overloads to pin a timezone.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/af8cee5b962eaaa1.
Report an issue: GitHub.