{"record":{"id":"4ae43cdd4df62ffd","repo":"apache/seatunnel","slug":"sql-operation-failed","errorCode":"SQL_OPERATION_FAILED","errorMessage":"Failed to check if database exists: {e.getMessage()}","messagePattern":"Failed to check if database exists: (.+?)","errorType":"error_code","errorClass":"DatabendConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/catalog/DatabendCatalog.java","lineNumber":139,"sourceCode":"    @Override\n    public String getDefaultDatabase() throws CatalogException {\n        return defaultDatabase;\n    }\n\n    @Override\n    public boolean databaseExists(String databaseName) throws CatalogException {\n        checkOpen();\n        try (Connection connection = getConnection()) {\n            try (ResultSet resultSet = connection.getMetaData().getSchemas()) {\n                while (resultSet.next()) {\n                    String foundDb = resultSet.getString(\"table_schema\");\n                    if (databaseName.equalsIgnoreCase(foundDb)) {\n                        return true;\n                    }\n                }\n            }\n        } catch (SQLException e) {\n            throw new DatabendConnectorException(\n                    DatabendConnectorErrorCode.SQL_OPERATION_FAILED,\n                    \"Failed to check if database exists: \" + e.getMessage(),\n                    e);\n        }\n        return false;\n    }\n\n    @Override\n    public List<String> listDatabases() throws CatalogException {\n        checkOpen();\n        try (Connection connection = getConnection()) {\n            List<String> databases = new ArrayList<>();\n            try (ResultSet resultSet = connection.getMetaData().getSchemas()) {\n                while (resultSet.next()) {\n                    String databaseName = resultSet.getString(\"TABLE_SCHEM\");\n                    databases.add(databaseName);\n                }\n            }","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/catalog/DatabendCatalog.java#L121-L157","documentation":"DatabendCatalog.databaseExists() inspects database metadata (via JDBC DatabaseMetaData) to test whether a database/schema exists. Any SQLException during that metadata query is wrapped as SQL_OPERATION_FAILED with this message. It is called by listTables, createTable, createDatabase and dropDatabase, so a failure here also blocks those operations.","triggerScenarios":"The JDBC metadata query executed inside databaseExists() throws — connection dropped mid-call, insufficient privileges to list schemas, driver-specific metadata quirks, or server-side query errors while fetching the schema list.","commonSituations":"Stale/timed-out connection after long idle, user lacking privileges to see the target database, Databend driver version with a metadata implementation bug, or network interruption between worker and Databend.","solutions":["Inspect the wrapped SQLException message/SQLState to identify the actual server-side or connection problem.","Verify the catalog connection still works (reopen the catalog or fix credentials/privileges with SHOW GRANTS for the user).","If the connection went stale, re-open the catalog before retrying the operation.","Upgrade/align the Databend JDBC driver if metadata calls are known-broken in your driver version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check with a direct query\nSELECT count(*) FROM information_schema.databases WHERE database_name = 'mydb';","typeGuard":null,"tryCatchPattern":"try {\n  exists = catalog.databaseExists(db);\n} catch (DatabendConnectorException e) {\n  if (e.getErrorCode() == SQL_OPERATION_FAILED) {\n    log.error(\"metadata query failed: {}\", e.getCause().getMessage());\n    // reopen catalog or retry with backoff\n  }\n}","preventionTips":["Keep catalog connections fresh; reopen after long idle periods","Grant the configured user privileges to list schemas","Use a JDBC driver version tested against your server version","Log and inspect SQLState codes to distinguish auth vs network vs SQL errors"],"tags":["databend","jdbc","metadata","sql"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}