apache/shardingsphere · error · SQLFeatureNotSupportedException

getDate

Error message

getDate

What it means

getDate(int columnIndex) is declared final and always throws in AbstractUnsupportedGeneratedKeysResultSet. GeneratedKeysResultSet only exposes string/numeric/object getters over the Comparable key values collected after INSERT, so java.sql.Date extraction is intentionally unimplemented.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java:52

/**
 * Unsupported {@code ResultSet} methods for generated keys.
 */
public abstract class AbstractUnsupportedGeneratedKeysResultSet extends AbstractUnsupportedOperationResultSet {
    
    @Override
    public final boolean getBoolean(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getBoolean");
    }
    
    @Override
    public final boolean getBoolean(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getBoolean");
    }
    
    @Override
    public final Date getDate(final int columnIndex) throws SQLException {
        throw new SQLFeatureNotSupportedException("getDate");
    }
    
    @Override
    public final Date getDate(final String columnLabel) throws SQLException {
        throw new SQLFeatureNotSupportedException("getDate");
    }
    
    @Override
    public final Date getDate(final int columnIndex, final Calendar cal) throws SQLException {
        throw new SQLFeatureNotSupportedException("getDate");
    }
    
    @Override
    public final Date getDate(final String columnLabel, final Calendar cal) throws SQLException {
        throw new SQLFeatureNotSupportedException("getDate");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. Use rs.getString(1) or rs.getObject(1) and convert to java.sql.Date explicitly (java.sql.Date.valueOf(String) or millis construction).
  2. If the generated key is a date/timestamp string, retrieve it as String from the datasource directly (e.g. SELECT the computed key column) instead of getGeneratedKeys().
  3. Wrap in try-catch for SQLFeatureNotSupportedException with a string-parse fallback.

Example fix

// before
Date d = rs.getDate(1);

// after
String raw = rs.getString(1);
Date d = raw == null ? null : java.sql.Date.valueOf(raw);
Defensive patterns

Strategy: try-catch

Validate before calling

Object key = rs.getObject(1);
if (key instanceof java.util.Date) { /* convert via getTime() */ } else { /* parse getString(1) */ }

Type guard

static boolean supportsDateGetters(ResultSet rs) {
    return !(rs.getClass().getName().endsWith("GeneratedKeysResultSet"));
}

Try / catch

try {
    d = rs.getDate(1);
} catch (SQLFeatureNotSupportedException e) {
    String raw = rs.getString(1);
    d = raw == null ? null : java.sql.Date.valueOf(raw);
}

Prevention

When it happens

Trigger: Calling rs.getDate(1) on the ResultSet returned by Statement.getGeneratedKeys() after an INSERT executed through the ShardingSphere driver.

Common situations: Generic insert-with-key helpers that materialize generated keys into various Java types (including Date for date-based primary keys). Code ported from MySQL Connector/J, which supports getDate on its generated-keys result set, breaking under jdbc:shardingsphere:.

Related errors


AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14). Data as JSON: /api/errors/fd50921c2f58eb25. Report an issue: GitHub.