apache/shardingsphere · error · SQLFeatureNotSupportedException

setNClob

Error message

setNClob

What it means

SQLFeatureNotSupportedException('setNClob') thrown by AbstractUnsupportedOperationPreparedStatement.setNClob(int, NClob). National-character LOB binding is unsupported: ShardingSphere's driver never materializes backend LOB handles at prepare time, so all NClob overloads are final and throw.

Source

Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationPreparedStatement.java:54

    
    @Override
    public final void addBatch(final String sql) throws SQLException {
        throw new SQLFeatureNotSupportedException("addBatch sql in PreparedStatement");
    }
    
    @Override
    public final ResultSetMetaData getMetaData() throws SQLException {
        throw new SQLFeatureNotSupportedException("getMetaData");
    }
    
    @Override
    public final void setNString(final int parameterIndex, final String x) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNString");
    }
    
    @Override
    public final void setNClob(final int parameterIndex, final NClob x) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNClob");
    }
    
    @Override
    public final void setNClob(final int parameterIndex, final Reader x) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNClob");
    }
    
    @Override
    public final void setNClob(final int parameterIndex, final Reader x, final long length) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNClob");
    }
    
    @Override
    public final void setNCharacterStream(final int parameterIndex, final Reader x) throws SQLException {
        throw new SQLFeatureNotSupportedException("setNCharacterStream");
    }
    
    @Override

View on GitHub (pinned to e952770a21)

Solutions

  1. Use setCharacterStream(1, new StringReader(text)) or setString for NCLOB-sized values on ShardingSphere.
  2. If an NClob object is unavoidable, read it (nclob.getCharacterStream()) and bind the Reader via setCharacterStream.
  3. Store nationalized text as ordinary CLOB/TEXT with a Unicode encoding and drop the N-type mapping.

Example fix

// before
ps.setNClob(1, nclob);

// after
ps.setCharacterStream(1, nclob.getCharacterStream(), nclob.length());
Defensive patterns

Strategy: fallback

Validate before calling

if (value instanceof NClob) { NClob n = (NClob) value; ps.setCharacterStream(idx, n.getCharacterStream(), n.length()); } else { ps.setClob(idx, (Clob) value); }

Prevention

When it happens

Trigger: ps.setNClob(1, nclob) on a ShardingSphere PreparedStatement; appears when porting Oracle/SQLServer NCLOB handling or when a generic binder dispatches on the value being an NClob instance.

Common situations: Large Unicode text columns (NCLOB) mapped to java.sql.NClob in entity code; ORM type handlers for nationalized CLOBs; code copied from a driver-agnostic tutorial.

Related errors


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