{"record":{"id":"50613cb2559db83f","repo":"apache/seatunnel","slug":"the-jdbc-source-statement-returned-no-connection","errorCode":null,"errorMessage":"The JDBC source statement returned no connection. Closing the cached connection to avoid reusing an unknown transaction.","messagePattern":"The JDBC source statement returned no connection\\. Closing the cached connection to avoid reusing an unknown transaction\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcInputFormat.java","lineNumber":187,"sourceCode":"            } finally {\n                statement = null;\n            }\n        }\n\n        hasNext = false;\n        splitTableSchema = null;\n        splitTableId = null;\n        finishReadTransaction(connection);\n    }\n\n    private Connection getStatementConnection() {\n        if (statement == null) {\n            return null;\n        }\n        try {\n            Connection connection = statement.getConnection();\n            if (connection == null) {\n                LOG.warn(\n                        \"The JDBC source statement returned no connection. \"\n                                + \"Closing the cached connection to avoid reusing an unknown \"\n                                + \"transaction.\");\n                chunkSplitter.close();\n            }\n            return connection;\n        } catch (SQLException e) {\n            LOG.warn(\n                    \"Failed to get the JDBC source connection from the current statement. \"\n                            + \"Closing the cached connection to avoid reusing an unknown \"\n                            + \"transaction.\",\n                    e);\n            chunkSplitter.close();\n            return null;\n        }\n    }\n\n    private void finishReadTransaction(Connection connection) {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcInputFormat.java#L169-L205","documentation":"JdbcInputFormat.getStatementConnection() extracts the Connection from the active JDBC statement. If the driver returns null (statement already closed or driver misbehavior), the format logs this warning and closes the cached connection via chunkSplitter to avoid reusing a connection with an unknown transaction state. It then returns null, which callers must treat as 'no valid connection'.","triggerScenarios":"Calling connection/getStatementConnection() when the statement is non-null but statement.getConnection() returns null — typically after the underlying connection was closed or the statement was invalidated by the driver.","commonSituations":"Driver-specific behavior after connection reset; transactional reads where a previous failure left the cached connection in an unknown state; network drop between statement creation and connection retrieval.","solutions":["Inspect driver behavior/version; upgrade to one that reliably returns the connection from the statement.","Check for earlier exceptions or connection-close calls that invalidated the statement before this point.","Handle the null return: treat it as connection loss and let the source retry/reopen rather than reusing the connection.","Review auto-commit/transaction config so the cached connection is not left in an unknown transaction state."],"exampleFix":"// before\nConnection conn = format.getStatementConnection();\nconn.setReadOnly(true);\n// after\nConnection conn = format.getStatementConnection();\nif (conn != null && !conn.isClosed()) {\n    conn.setReadOnly(true);\n}","handlingStrategy":"type-guard","validationCode":"// Guard before using the returned connection\nif (conn == null || conn.isClosed()) {\n    LOG.warn(\"No usable connection — request a retry/reopen\");\n    return;\n}","typeGuard":"boolean isUsable(Connection c) {\n    try { return c != null && !c.isClosed(); } catch (SQLException e) { return false; }\n}","tryCatchPattern":"try {\n    Connection c = format.getStatementConnection();\n    if (c == null) { /* connection discarded; trigger task retry */ }\n} catch (Exception e) { /* fail task so framework recreates the connection */ }","preventionTips":["Configure keepalive/socket timeouts above job duration","Upgrade drivers known to return null from statement.getConnection()","Monitor earlier warnings indicating connection invalidation"],"tags":["jdbc","connection","transaction","driver","null"],"backgroundTag":"connection-closed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}