apache/shardingsphere · error · SQLFeatureNotSupportedException

getBoolean

Error message

getBoolean

What it means

AbstractUnsupportedGeneratedKeysResultSet makes getBoolean(int columnIndex) final and always throwing. The ResultSet returned by Statement.getGeneratedKeys() in the ShardingSphere driver is a GeneratedKeysResultSet holding plain Comparable key values (usually numeric auto-increment ids) and only implements string/numeric/object getters, so there is no boolean conversion path.

Source

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

import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;

/**
 * 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

View on GitHub (pinned to e952770a21)

Solutions

  1. Use the supported getter matching real key types: rs.getLong(1), rs.getInt(1), rs.getBigDecimal(1), or rs.getString(1).
  2. Use rs.getObject(1) and convert in Java if the key type varies (e.g. ((Number) obj).longValue()).
  3. Remove the getBoolean branch for generated-key result sets; auto-increment keys are never boolean.
  4. As a last resort wrap in try-catch for SQLFeatureNotSupportedException and re-read via getString.

Example fix

// before
boolean ok = rs.getBoolean(1);

// after
long id = rs.getLong(1);
Defensive patterns

Strategy: try-catch

Validate before calling

// Generated keys are scalar; before reading, choose a supported getter:
Object key = rs.getObject(1); // never throws SQLFeatureNotSupportedException here

Type guard

static boolean isShardingGeneratedKeys(ResultSet rs) {
    return rs instanceof org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet
        || rs.getClass().getName().endsWith("GeneratedKeysResultSet");
}

Try / catch

try {
    flag = rs.getBoolean(1);
} catch (SQLFeatureNotSupportedException e) {
    flag = rs.getLong(1) != 0; // or parse rs.getString(1)
}

Prevention

When it happens

Trigger: Executing an INSERT through the ShardingSphere driver with Statement.RETURN_GENERATED_KEYS, then calling rs.getBoolean(1) while iterating the ResultSet from getGeneratedKeys().

Common situations: Generic key-mapping frameworks or copy-pasted DAO code that reads every generated key with getBoolean regardless of key type. Migrating working code from a native MySQL/PostgreSQL driver to jdbc:shardingsphere: where the vendor result set silently coerced values to boolean.

Related errors


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