{"record":{"id":"1bddaf7cfe75a7fe","repo":"prestodb/presto","slug":"fetch-direction-must-be-fetch-forward","errorCode":null,"errorMessage":"Fetch direction must be FETCH_FORWARD","messagePattern":"Fetch direction must be FETCH_FORWARD","errorType":"validation","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":701,"sourceCode":"            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"relative\");\n    }\n\n    @Override\n    public boolean previous()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"previous\");\n    }\n\n    @Override\n    public void setFetchDirection(int direction)\n            throws SQLException\n    {\n        checkOpen();\n        if (direction != FETCH_FORWARD) {\n            throw new SQLException(\"Fetch direction must be FETCH_FORWARD\");\n        }\n    }\n\n    @Override\n    public int getFetchDirection()\n            throws SQLException\n    {\n        checkOpen();\n        return FETCH_FORWARD;\n    }\n\n    @Override\n    public void setFetchSize(int rows)\n            throws SQLException\n    {\n        checkOpen();\n        if (rows < 0) {\n            throw new SQLException(\"Rows is negative\");","sourceCodeStart":683,"sourceCodeEnd":719,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L683-L719","documentation":"setFetchDirection is a validation guard in PrestoResultSet: after checkOpen(), any direction other than ResultSet.FETCH_FORWARD is rejected with this SQLException, because Presto result sets can only be iterated forward.","triggerScenarios":"Calling setFetchDirection(FETCH_REVERSE) or setFetchDirection(FETCH_UNKNOWN) on a PrestoResultSet or its Statement.","commonSituations":"Generic connection-pool or framework initialization code that sets FETCH_UNKNOWN by default; ported code from drivers that accept any fetch direction.","solutions":["Pass ResultSet.FETCH_FORWARD explicitly, or do not call setFetchDirection at all","Set fetch direction only when the code detects a non-Presto JDBC driver","Guard the call in a try-catch if the setting is purely advisory for your use case"],"exampleFix":"// before\nrs.setFetchDirection(ResultSet.FETCH_UNKNOWN);\n// after\nrs.setFetchDirection(ResultSet.FETCH_FORWARD);","handlingStrategy":"validation","validationCode":"if (direction != ResultSet.FETCH_FORWARD) {\n    throw new IllegalArgumentException(\"Presto supports only FETCH_FORWARD\");\n}\nrs.setFetchDirection(direction);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass ResultSet.FETCH_FORWARD or omit the call","Skip setFetchDirection when the driver is Presto (check conn.getMetaData().getDatabaseProductName())","Do not apply shared JDBC tuning code blindly to Presto connections"],"tags":["jdbc","fetch-direction","forward-only-resultset"],"backgroundTag":"jdbc-fetch-direction-rejected","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}