apache/shardingsphere · error · ColumnLabelNotFoundException
21
21
Error message
Can not find column label '%s'.
What it means
ColumnLabelNotFoundException (SQLState/error code 21 family) thrown by DatabaseMetaDataResultSet.findColumn when the requested column label is not a key in columnLabelIndexMap. This metadata ResultSet is backed by in-memory rows produced by ShardingSphere's DatabaseMetaData implementation, so only the exact labels it defines are resolvable.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/resultset/DatabaseMetaDataResultSet.java:378
}
@Override
public Object getObject(final int columnIndex) throws SQLException {
checkClosed();
checkColumnIndex(columnIndex);
return currentDatabaseMetaDataObject.getObject(columnIndex);
}
@Override
public Object getObject(final String columnLabel) throws SQLException {
return getObject(findColumn(columnLabel));
}
@Override
public int findColumn(final String columnLabel) throws SQLException {
checkClosed();
if (!columnLabelIndexMap.containsKey(columnLabel)) {
throw new ColumnLabelNotFoundException(columnLabel).toSQLException();
}
return columnLabelIndexMap.get(columnLabel);
}
@Override
public int getType() throws SQLException {
checkClosed();
return type;
}
@Override
public int getConcurrency() throws SQLException {
checkClosed();
return concurrency;
}
@Override
public void setFetchDirection(final int direction) throws SQLException {View on GitHub (pinned to e952770a21)
Solutions
- Inspect the result set's metadata (ResultSetMetaData.getColumnLabel) at runtime and use the exact labels present.
- Read columns by index instead of label for metadata result sets.
- Check the JDBC/DatabaseMetaData spec for which columns the specific metadata method returns, and fix the label name.
Example fix
// before
rs = meta.getTables(null, null, "%", null);
String db = rs.getString("DATABASE_NAME"); // label not in getTables result
// after
String db = rs.getString("TABLE_CAT"); // spec-defined label Defensive patterns
Strategy: validation
Validate before calling
int idx = -1; try { idx = rs.findColumn("TABLE_NAME"); } catch (SQLException ok) { /* fall back by spec order */ } Try / catch
catch (SQLException ex) { // ColumnLabelNotFoundException: enumerate available labels
for (int i=1;i<=rs.getMetaData().getColumnCount();i++) log(rs.getMetaData().getColumnLabel(i)); } Prevention
- Use spec-defined labels for each DatabaseMetaData method
- Prefer positional access on metadata result sets
- Verify label existence with findColumn before getString(String)
When it happens
Trigger: Calling getString/findColumn(String) on a ResultSet returned by DatabaseMetaData methods (getTables, getColumns, getIndexInfo, ...) with a label that does not exist for that metadata result set — e.g. asking for 'TABLE_NAME' on a result set that does not expose it, or a case-sensitive mismatch.
Common situations: Framework/schema-tooling code assuming a specific metadata column exists across drivers; porting tools written for another DB's metadata layout; typos or wrong-case labels; reading the wrong metadata method's result set.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/bbe634aefe9df2d6.
Report an issue: GitHub.