apache/shardingsphere · error · SQLFeatureNotSupportedException
getTimestamp
Error message
getTimestamp
What it means
getTimestamp(int columnIndex) is final and always throws SQLFeatureNotSupportedException in AbstractUnsupportedGeneratedKeysResultSet. Although GeneratedKeysResultSet stores Comparable values (which could be timestamps), it implements only getString/getNumeric/getObject accessors, and Timestamp extraction is deliberately delegated to the unsupported base class.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java:92
@Override
public final Time getTime(final int columnIndex, final Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException("getTime");
}
@Override
public final Time getTime(final String columnLabel, final Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException("getTime");
}
@Override
public final Time getTime(final String columnLabel) throws SQLException {
throw new SQLFeatureNotSupportedException("getTime");
}
@Override
public final Timestamp getTimestamp(final int columnIndex) throws SQLException {
throw new SQLFeatureNotSupportedException("getTimestamp");
}
@Override
public final Timestamp getTimestamp(final String columnLabel) throws SQLException {
throw new SQLFeatureNotSupportedException("getTimestamp");
}
@Override
public final Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException("getTimestamp");
}
@Override
public final Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException {
throw new SQLFeatureNotSupportedException("getTimestamp");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Use rs.getString(1) and convert with java.sql.Timestamp.valueOf(String) when the key is a timestamp literal.
- Use rs.getObject(1) and convert via ((java.util.Date) obj).getTime() or Timestamp.valueOf(obj.toString()).
- For numeric keys use getLong/getBigDecimal instead.
- Catch SQLFeatureNotSupportedException and fall back to string parsing.
Example fix
// before Timestamp ts = rs.getTimestamp(1); // after String raw = rs.getString(1); Timestamp ts = raw == null ? null : java.sql.Timestamp.valueOf(raw);
Defensive patterns
Strategy: try-catch
Validate before calling
Object key = rs.getObject(1); // timestamp keys arrive as Comparable; convert from runtime type
Type guard
static boolean isShardingGeneratedKeys(ResultSet rs) {
return rs.getClass().getName().endsWith("GeneratedKeysResultSet");
} Try / catch
try {
ts = rs.getTimestamp(1);
} catch (SQLFeatureNotSupportedException e) {
Object v = rs.getObject(1);
ts = v == null ? null : java.sql.Timestamp.valueOf(v.toString());
} Prevention
- Read generated keys with getLong/getBigDecimal/getString/getObject only.
- Convert timestamp-like keys via Timestamp.valueOf of the string form.
- Include getGeneratedKeys flows in driver-migration test suites.
When it happens
Trigger: Calling rs.getTimestamp(1) on the ResultSet from Statement.getGeneratedKeys() after an INSERT via the ShardingSphere driver.
Common situations: Insert helpers mapping generated keys to Timestamp-typed ids (e.g. MongoDB ObjectId-adjacent patterns or timestamp-based keys), or generic mappers copying vendor-driver behavior. Common when porting MySQL Connector/J code that supports getTimestamp on generated keys.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/5d89e2b7a325a8fd.
Report an issue: GitHub.