{"record":{"id":"5c6d7b87c09fc616","repo":"apache/shardingsphere","slug":"updatenstring","errorCode":null,"errorMessage":"updateNString","messagePattern":"updateNString","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedUpdateOperationSQLFederationResultSet.java","lineNumber":144,"sourceCode":"    \n    @Override\n    public final void updateBigDecimal(final String columnLabel, final BigDecimal x) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateBigDecimal\");\n    }\n    \n    @Override\n    public final void updateString(final int columnIndex, final String x) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateString\");\n    }\n    \n    @Override\n    public final void updateString(final String columnLabel, final String x) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateString\");\n    }\n    \n    @Override\n    public final void updateNString(final int columnIndex, final String nString) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateNString\");\n    }\n    \n    @Override\n    public final void updateNString(final String columnLabel, final String nString) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateNString\");\n    }\n    \n    @Override\n    public final void updateBytes(final int columnIndex, final byte[] x) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateBytes\");\n    }\n    \n    @Override\n    public final void updateBytes(final String columnLabel, final byte[] x) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"updateBytes\");\n    }\n    \n    @Override","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/resultset/AbstractUnsupportedUpdateOperationSQLFederationResultSet.java#L126-L162","documentation":"The federation ResultSet returned by ShardingSphere's SQL federation engine overrides every updateXxx method in AbstractUnsupportedUpdateOperationSQLFederationResultSet to throw SQLFeatureNotSupportedException, message 'updateNString' for the national-character-string updater (column-index overload). NString in-place writes are unsupported because the federated result is a read-only, in-memory computed view, not an updatable database cursor.","triggerScenarios":"Calling ResultSet.updateNString(int columnIndex, String nString) on a federation ResultSet (statement executed via sql_federation, e.g. cross-shard join). Encountered in i18n-heavy applications or generic column writers that handle NVARCHAR/NCHAR via the N-variants of JDBC methods.","commonSituations":"Code that uniformly uses updateNString for Unicode-safe writes running against a newly federated ShardingSphere datasource; framework migration where NVARCHAR editing code paths receive federation result sets; sqlFederation enabled for queries previously served by the underlying driver's updatable cursor.","solutions":["Read with getNString(columnIndex) and perform writes through a PreparedStatement UPDATE using setNString, keyed on the primary key.","Check rs.getConcurrency() before update-cursor code; for read-only concurrency use statement-based writes only.","Adjust the sql_federation rule so the statement bypasses federation and returns the backend driver's ResultSet."],"exampleFix":"// before\nrs.updateNString(5, \"こんにちは\");  // SQLFeatureNotSupportedException: updateNString\n\n// after\ntry (PreparedStatement upd = conn.prepareStatement(\"UPDATE messages SET body = ? WHERE id = ?\")) {\n    upd.setNString(1, \"こんにちは\");\n    upd.setLong(2, rs.getLong(1));\n    upd.executeUpdate();\n}","handlingStrategy":"try-catch","validationCode":"if (rs.getConcurrency() != ResultSet.CONCUR_UPDATABLE) {\n    // rs.updateNString(...) unsupported; use UPDATE + setNString\n}","typeGuard":"private static boolean supportsRowUpdates(final ResultSet rs) throws SQLException {\n    return rs.getConcurrency() == ResultSet.CONCUR_UPDATABLE;\n}","tryCatchPattern":"try {\n    rs.updateNString(5, text);\n} catch (final SQLFeatureNotSupportedException ignored) {\n    try (PreparedStatement upd = conn.prepareStatement(\"UPDATE messages SET body = ? WHERE id = ?\")) {\n        upd.setNString(1, text);\n        upd.setLong(2, rs.getLong(1));\n        upd.executeUpdate();\n    }\n}","preventionTips":["Use setNString on a keyed UPDATE for Unicode column writes.","Verify result-set concurrency before using N-variant update methods.","Track which statements are federated when i18n columns are involved."],"tags":["jdbc","resultset","sql-federation","read-only","shardingsphere","nstring"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}