apache/shardingsphere · error · SQLFeatureNotSupportedException
getMetaData
Error message
getMetaData
What it means
SQLFeatureNotSupportedException('getMetaData') thrown by AbstractUnsupportedOperationPreparedStatement.getMetaData(). ShardingSphere resolves the actual target database only at execution time (routing depends on bind values and sharding rules), so it cannot produce a ResultSetMetaData for a PreparedStatement before execution; the method is final and always throws. ShardingSpherePreparedStatement computes column metadata only after executing (columnLabelAndIndexMap).
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationPreparedStatement.java:44
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
/**
* Unsupported {@code PreparedStatement} methods.
*/
public abstract class AbstractUnsupportedOperationPreparedStatement extends AbstractStatementAdapter implements PreparedStatement {
@Override
public final void addBatch(final String sql) throws SQLException {
throw new SQLFeatureNotSupportedException("addBatch sql in PreparedStatement");
}
@Override
public final ResultSetMetaData getMetaData() throws SQLException {
throw new SQLFeatureNotSupportedException("getMetaData");
}
@Override
public final void setNString(final int parameterIndex, final String x) throws SQLException {
throw new SQLFeatureNotSupportedException("setNString");
}
@Override
public final void setNClob(final int parameterIndex, final NClob x) throws SQLException {
throw new SQLFeatureNotSupportedException("setNClob");
}
@Override
public final void setNClob(final int parameterIndex, final Reader x) throws SQLException {
throw new SQLFeatureNotSupportedException("setNClob");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Execute the query first and call rs.getMetaData() on the returned ResultSet — ShardingSphere delegates that to the routed backend.
- For exporters, switch to a lazy header model that reads metadata from row 1 / ResultSet after execution.
- Catch SQLFeatureNotSupportedException and defer metadata retrieval to post-execution.
Example fix
// before ResultSetMetaData md = ps.getMetaData(); int cols = md.getColumnCount(); ResultSet rs = ps.executeQuery(); // after ResultSet rs = ps.executeQuery(); int cols = rs.getMetaData().getColumnCount();
Defensive patterns
Strategy: validation
Validate before calling
// ShardingSphere resolves columns only after execution: read metadata from the ResultSet
// if (!driverName.contains("shardingsphere")) use ps.getMetaData(), else execute first Try / catch
ResultSetMetaData md;
try { md = ps.getMetaData(); }
catch (final SQLFeatureNotSupportedException e) { md = null; } // re-read from rs.getMetaData() after execute Prevention
- Read column metadata from ResultSet.getMetaData() after execution
- Design exporters/table models lazily
- Do not pre-count columns from PreparedStatement metadata
When it happens
Trigger: ps.getMetaData() before ps.executeQuery()/executeUpdate() on a ShardingSphere PreparedStatement. Common in frameworks that pre-render column headers from PreparedStatement metadata (report tools, table models) and in pagination code that counts result columns first.
Common situations: Swing/SWT table models or Excel/CSV exporters built on PreparedStatement.getMetaData; JasperReports subreports; migration from drivers with server-side prepare (PostgreSQL, Oracle) where getMetaData worked pre-execution.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/12175bbcd93a1192.
Report an issue: GitHub.