apache/shardingsphere · error · SQLFeatureNotSupportedException
setNString
Error message
setNString
What it means
SQLFeatureNotSupportedException('setNString') thrown by AbstractUnsupportedOperationPreparedStatement.setNString(int, String). N-prefixed JDBC methods target SQL NATIONAL CHARACTER (NCHAR/NVARCHAR) columns; ShardingSphere's parameter pipeline passes plain objects to routed backend statements and has no N-type handling, so the final override always throws.
Source
Thrown at jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedOperationPreparedStatement.java:49
/**
* Unsupported {@code PreparedStatement} methods.
*/
public abstract class AbstractUnsupportedOperationPreparedStatement extends AbstractStatementAdapter implements PreparedStatement {
@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");
}
@OverrideView on GitHub (pinned to e952770a21)
Solutions
- Replace with ps.setString(index, value); virtually all backends implicitly convert VARCHAR literals to N-columns.
- In Hibernate, remove @Nationalized (or set hibernate.use_nationalized_character_data=false globally).
- Ensure server/driver encoding (e.g. MySQL utf8mb4, PostgreSQL UTF8) makes N-types unnecessary.
Example fix
// before ps.setNString(1, name); // after ps.setString(1, name);
Defensive patterns
Strategy: validation
Validate before calling
// Replace every N-variant with the plain one before running on ShardingSphere ps.setString(index, value); // instead of ps.setNString(index, value)
Prevention
- Grep for setN when adopting the ShardingSphere driver
- Disable Hibernate @Nationalized / use_nationalized_character_data
- Rely on UTF-8 database encoding instead of N-types
When it happens
Trigger: ps.setNString(1, value) on a ShardingSphere PreparedStatement; typically from Oracle/SQLServer-oriented code targeting NVARCHAR/NCHAR columns, or ORMs that auto-select setNString for nationalized @Nationalized/@Type mappings.
Common situations: Apps written against Oracle NCHAR/NVARCHAR2 or SQL Server nvarchar schemas then pointed at jdbc:shardingsphere:; Hibernate entities annotated @Nationalized; code following JDBC tutorials for internationalized text.
Related errors
AI-assisted analysis of apache/shardingsphere@e952770a21 (2026-08-14).
Data as JSON: /api/errors/f010a8ace04cebb3.
Report an issue: GitHub.