prestodb/presto · error · SQLException

Statement is closed

Error message

Statement is closed

What it means

connection() is the shared liveness guard for PrestoStatement: when the WeakReference to the PrestoConnection has been cleared (statement closed), it throws this SQLException. Every checkOpen() call funnels through here, so any operation on a closed statement surfaces this error.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:657

            PrestoResultSet resultSet = currentResult.get();
            if (resultSet != null) {
                resultSet.partialCancel();
            }
        }
    }

    protected final void checkOpen()
            throws SQLException
    {
        connection();
    }

    protected final PrestoConnection connection()
            throws SQLException
    {
        PrestoConnection connection = this.connection.get();
        if (connection == null) {
            throw new SQLException("Statement is closed");
        }
        if (connection.isClosed()) {
            throw new SQLException("Connection is closed");
        }
        return connection;
    }

    private void closeResultSet()
            throws SQLException
    {
        ResultSet resultSet = currentResult.getAndSet(null);
        if (resultSet != null) {
            resultSet.close();
        }
    }

    private static boolean validFetchDirection(int direction)
    {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Do not use a Statement after close(); create a new one via Connection.createStatement
  2. Check for premature closure in try-with-resources scoping (statement closed before results are consumed)
  3. Catch SQLException in generic JDBC frameworks that may operate on closed statements
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:657 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/0890b9971d4c4896. Report an issue: GitHub.