{"record":{"id":"402a30a56824ee47","repo":"apache/seatunnel","slug":"connect-database-failed-402a30","errorCode":"CONNECT_DATABASE_FAILED","errorMessage":"Sink table %s does not exist and schema_save_mode is %s.","messagePattern":"Sink table (.+?) does not exist and schema_save_mode is (.+?)\\.","errorType":"error_code","errorClass":"JdbcConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkFactory.java","lineNumber":310,"sourceCode":"                    dialect.getJdbcConnectionProvider(sinkConfig.getJdbcConnectionConfig())\n                            .getOrEstablishConnection()) {\n                return;\n            }\n        }\n\n        try (Catalog catalog = optionalCatalog.get()) {\n            catalog.open();\n\n            TablePath targetTablePath = resolveDryRunTargetTablePath(context);\n            if (targetTablePath == null) {\n                // Custom-query sink or unresolvable table name: connectivity is all we can check.\n                return;\n            }\n\n            if (!catalog.tableExists(targetTablePath)) {\n                if (config.get(JdbcSinkOptions.SCHEMA_SAVE_MODE)\n                        == SchemaSaveMode.ERROR_WHEN_SCHEMA_NOT_EXIST) {\n                    throw new JdbcConnectorException(\n                            JdbcConnectorErrorCode.CONNECT_DATABASE_FAILED,\n                            String.format(\n                                    \"Sink table %s does not exist and schema_save_mode is %s.\",\n                                    targetTablePath.getFullName(),\n                                    SchemaSaveMode.ERROR_WHEN_SCHEMA_NOT_EXIST));\n                }\n                // Table will be created by save mode at runtime; nothing more to validate.\n                return;\n            }\n\n            CatalogTable targetTable = catalog.getTable(targetTablePath);\n            Set<String> targetColumns =\n                    targetTable.getTableSchema().getColumns().stream()\n                            .map(column -> column.getName().toLowerCase(Locale.ROOT))\n                            .collect(Collectors.toSet());\n            List<String> missingColumns =\n                    context.getCatalogTable().getTableSchema().getColumns().stream()\n                            .map(Column::getName)","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/sink/JdbcSinkFactory.java#L292-L328","documentation":"During sink validation (dry-run), if the target table does not exist and schema_save_mode=ERROR_WHEN_SCHEMA_NOT_EXIST, JdbcSinkFactory throws CONNECT_DATABASE_FAILED stating the sink table is missing. This is a user-configuration guard: the library is told to fail rather than auto-create the schema.","triggerScenarios":"Running a job (or its validation phase, validateConnectionForDryRun) where catalog.tableExists(targetTablePath) returns false and the config has schema_save_mode = ERROR_WHEN_SCHEMA_NOT_EXIST.","commonSituations":"Typo in table/database name in the sink config; table expected to be pre-created by a DBA but not yet created; wrong catalog/database URL pointing at another schema; migrating jobs between environments where the table only exists in one.","solutions":["Create the target table in the database before running the job, or set schema_save_mode=CREATE_SCHEMA_WHEN_NOT_EXIST (or other auto mode) in the sink config","Check the database/table name spelling and that the connection URL points to the intended database/schema","Verify the job's user has permission to see the table (some catalogs hide tables from unprivileged users)","If auto-creating, also review schema_save_mode-related options like template sql to control the generated DDL"],"exampleFix":"// before\nsink {\n  Jdbc {\n    schema_save_mode = \"ERROR_WHEN_SCHEMA_NOT_EXIST\"\n  }\n}\n// after\nsink {\n  Jdbc {\n    schema_save_mode = \"CREATE_SCHEMA_WHEN_NOT_EXIST\"\n  }\n}","handlingStrategy":"validation","validationCode":"// before the job: check table existence\ntry (Connection c = DriverManager.getConnection(url, user, pass);\n     ResultSet rs = c.getMetaData().getTables(null, schema, table, new String[]{\"TABLE\"})) {\n  if (!rs.next()) {\n    // create table or set schema_save_mode = CREATE_SCHEMA_WHEN_NOT_EXIST\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  sinkFactory.createSink(context);\n} catch (JdbcConnectorException e) {\n  if (e.getMessage().contains(\"does not exist\")) {\n    // create the table, then resubmit the job\n  }\n}","preventionTips":["Verify table existence with the same credentials the job will use","Set schema_save_mode explicitly and consciously (CREATE vs ERROR)","Watch for case sensitivity differences across environments","Keep DDL migrations in sync between dev/staging/prod"],"tags":["jdbc","schema","validation","config"],"backgroundTag":"resource-not-found","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"}