apache/shardingsphere · error · SQLFeatureNotSupportedException

getParameterType

Error message

getParameterType

What it means

SQLFeatureNotSupportedException thrown by AbstractUnsupportedOperationParameterMetaData.getParameterType(int). ShardingSphere parses SQL locally for sharding/encryption routing and never performs a backend PREPARE, so the java.sql.Types code of each '?' is unknown; the concrete ShardingSphereParameterMetaData only implements getParameterCount(), leaving this final throwing method.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationParameterMetaData.java:53

    
    @Override
    public final boolean isSigned(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("isSigned");
    }
    
    @Override
    public final int getPrecision(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getPrecision");
    }
    
    @Override
    public final int getScale(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getScale");
    }
    
    @Override
    public final int getParameterType(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getParameterType");
    }
    
    @Override
    public final String getParameterTypeName(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getParameterTypeName");
    }
    
    @Override
    public final String getParameterClassName(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getParameterClassName");
    }
    
    @Override
    public final int getParameterMode(final int parameter) throws SQLException {
        throw new SQLFeatureNotSupportedException("getParameterMode");
    }
}

View on GitHub (pinned to e952770a21)

Solutions

  1. Declare jdbcType/javaType explicitly in mappings: MyBatis #{name,jdbcType=INTEGER}, and set jdbcTypeForNull=NULL in mybatis-config when binding nulls.
  2. Avoid UnknownTypeHandler: register concrete typeHandlers for the parameter's Java type so getParameterType is never consulted.
  3. Catch SQLFeatureNotSupportedException in generic layers and default to Types.VARCHAR or a caller-supplied type hint.

Example fix

<!-- before -->
<select id="getUser">SELECT * FROM user WHERE status = #{status}</select>

<!-- after -->
<select id="getUser">SELECT * FROM user WHERE status = #{status,jdbcType=TINYINT}</select>
Defensive patterns

Strategy: validation

Validate before calling

// MyBatis: prevent UnknownTypeHandler from ever calling getParameterType
// mybatis-config.xml: always declare jdbcType per parameter
<settings><setting name="jdbcTypeForNull" value="NULL"/></settings>

Try / catch

try { sqlType = pmd.getParameterType(1); } catch (final SQLFeatureNotSupportedException e) { sqlType = Types.VARCHAR; /* conservative default */ }

Prevention

When it happens

Trigger: ps.getParameterMetaData().getParameterType(i) on ShardingSphere JDBC. Most common real trigger: MyBatis UnknownTypeHandler (used when a #{} parameter has no explicit javaType/jdbcType) calls getParameterType to choose a TypeHandler.

Common situations: MyBatis mappers with untyped #{param} placeholders (especially null-valued parameters or Object-typed fields) after introducing the ShardingSphere driver; generic query frameworks (Apache DbUtils, Spring SimpleJdbcInsert in some modes) that auto-detect bind types.

Related errors


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