{"record":{"id":"6ecd65772dee3d8d","repo":"t8y2/dbx","slug":"not-connected-6ecd65","errorCode":null,"errorMessage":"Not connected","messagePattern":"Not connected","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java","lineNumber":126,"sourceCode":"            this::resetSchemaSQL\n        );\n    }\n\n    @Override\n    public QueryResult executeBatch(List<String> statements, String schema) {\n        return BatchExecutor.executeBatchStatements(\n            requireConnected(),\n            statements,\n            schema,\n            this::setSchemaSQL,\n            this::resetSchemaSQL\n        );\n    }\n\n    protected Connection requireConnected() {\n        Connection conn = getConnection();\n        if (conn == null) {\n            throw new IllegalStateException(\"Not connected\");\n        }\n        return conn;\n    }\n\n    protected static <T> T unchecked(ThrowingSupplier<T> supplier) {\n        try {\n            return supplier.get();\n        } catch (RuntimeException e) {\n            throw e;\n        } catch (Exception e) {\n            throw new RuntimeException(e);\n        }\n    }\n\n    protected static void uncheckedVoid(ThrowingRunnable runnable) {\n        unchecked(() -> {\n            runnable.run();\n            return null;","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/common/src/main/java/com/dbx/agent/BaseDatabaseAgent.java#L108-L144","documentation":"requireConnected is a guard used by connection-backed operations (conn, startTableRead, executeTransaction, executeBatch). It fetches the current connection and throws 'Not connected' when getConnection() returns null, i.e. no connection is currently established.","triggerScenarios":"Calling executeBatch/startTableRead/executeTransaction (or conn) before connect(), or after the connection was closed, reset, or never established due to an earlier connect failure.","commonSituations":"Operations issued after a dropped connection; using a shared agent from another thread after close(); forgetting to call connect in setup; lazy connection lost after timeout.","solutions":["Call connect() with valid ConnectParams before running database operations","Reconnect after any close/disconnect and before retrying the operation","Check the connection state (e.g. via getConnection() != null) before issuing calls","Investigate why the connection was closed (timeout, error, lifecycle hook) if connect was previously called"],"exampleFix":"// before\nagent.executeBatch(statements); // throws if not connected\n// after\nif (agent.getConnection() == null) {\n    agent.connect(connectParams);\n}\nagent.executeBatch(statements);","handlingStrategy":"validation","validationCode":"if (agent.getConnection() == null) {\n    agent.connect(connectParams);\n}\nagent.executeBatch(statements);","typeGuard":"boolean isConnected(BaseDatabaseAgent a) {\n    return a.getConnection() != null;\n}","tryCatchPattern":"try {\n    agent.executeTransaction(tx);\n} catch (IllegalStateException e) {\n    if (\"Not connected\".equals(e.getMessage())) {\n        agent.connect(connectParams);\n        agent.executeTransaction(tx);\n    }\n}","preventionTips":["Check getConnection() != null before connection-backed operations","Centralize connect/reconnect logic behind a helper","Handle connection drops (timeouts, server restarts) with reconnect-on-demand","Avoid long-lived connections; re-establish after idle periods"],"tags":["jdbc","connection-state","illegal-state"],"backgroundTag":"jdbc-not-connected","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}