{"record":{"id":"6c87267c67b04066","repo":"apache/shardingsphere","slug":"setfetchsize","errorCode":null,"errorMessage":"setFetchSize","messagePattern":"setFetchSize","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java","lineNumber":182,"sourceCode":"    \n    @Override\n    public final Reader getCharacterStream(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getCharacterStream\");\n    }\n    \n    @Override\n    public final void setFetchDirection(final int direction) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"setFetchDirection\");\n    }\n    \n    @Override\n    public final int getFetchDirection() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getFetchDirection\");\n    }\n    \n    @Override\n    public final void setFetchSize(final int rows) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"setFetchSize\");\n    }\n    \n    @Override\n    public final int getFetchSize() throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getFetchSize\");\n    }\n    \n    @Override\n    public final Blob getBlob(final int columnIndex) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getBlob\");\n    }\n    \n    @Override\n    public final Blob getBlob(final String columnLabel) throws SQLException {\n        throw new SQLFeatureNotSupportedException(\"getBlob\");\n    }\n    \n    @Override","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java#L164-L200","documentation":"setFetchSize(int rows) on the generated-keys ResultSet always throws SQLFeatureNotSupportedException(\"setFetchSize\") (AbstractUnsupportedGeneratedKeysResultSet:182). The ShardingSphere GeneratedKeysResultSet streams from an in-memory Iterator of key values — there is no driver-level fetch window to size, so the hint API is deliberately unsupported.","triggerScenarios":"Calling resultSet.setFetchSize(n) (e.g. rs.setFetchSize(100) in a batch-insert loop) on the ResultSet returned by getGeneratedKeys() — very common in batch-processing templates that apply fetch-size hints to every result set they touch.","commonSituations":"Batch/ETL frameworks that set fetch size to control memory on every ResultSet; Spring Batch or streaming readers tuned for MySQL (useFetchSizeTrick) applying hints to key result sets; code that worked against a permissive native driver and throws after switching to ShardingSphere-JDBC.","solutions":["Apply fetch-size hints to the Statement before execution (statement.setFetchSize(n)) rather than to the generated-keys ResultSet.","Skip the call entirely for key result sets — data is already materialized in memory.","In shared helpers, guard with try-catch (SQLFeatureNotSupportedException) and continue.","Separate INSERT/batch-generated-keys handling from SELECT streaming logic so hints target only query result sets."],"exampleFix":"// before\nResultSet keys = stmt.getGeneratedKeys();\nkeys.setFetchSize(100); // throws\n\n// after\nPreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);\nps.setFetchSize(100);\nResultSet keys = ps.getGeneratedKeys();","handlingStrategy":"try-catch","validationCode":"PreparedStatement ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);\nps.setFetchSize(batchSize); // hint goes on the statement","typeGuard":"private static boolean supportsFetchHints(ResultSet rs) {\n    return !rs.getClass().getName().endsWith(\"GeneratedKeysResultSet\");\n}","tryCatchPattern":"try {\n    rs.setFetchSize(100);\n} catch (SQLFeatureNotSupportedException ignore) {\n    // keys are already in memory; no fetch window applies\n}","preventionTips":["Apply fetch-size tuning only to SELECT streaming paths.","Set hints before execution on the Statement object.","Guard framework helpers that uniformly configure every ResultSet."],"tags":["jdbc","shardingsphere","generated-keys","fetch-size","batch","unsupported-operation"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}