{"record":{"id":"4814f212fc79177e","repo":"apache/seatunnel","slug":"sql-operation-failed-4814f2","errorCode":"SQL_OPERATION_FAILED","errorMessage":"Failed to prepare custom statement: ${e.getMessage()}","messagePattern":"Failed to prepare custom statement: (.+?)","errorType":"error_code","errorClass":"DatabendConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/sink/DatabendSinkWriter.java","lineNumber":143,"sourceCode":"\n        log.info(\"DatabendSinkWriter constructor - catalogTable: {}\", catalogTable);\n        log.info(\"DatabendSinkWriter constructor - tableSchema: {}\", tableSchema);\n        log.info(\n                \"DatabendSinkWriter constructor - rowType: {}\", catalogTable.getSeaTunnelRowType());\n        log.info(\"DatabendSinkWriter constructor - target table path: {}\", sinkTablePath);\n        log.info(\"DatabendSinkWriter constructor - CDC mode: {}\", isCdcMode);\n\n        // if custom SQL is provided, use it directly\n        if (customSql != null && !customSql.isEmpty()) {\n            this.insertSql = customSql;\n            log.info(\"Using custom SQL: {}\", insertSql);\n            try {\n                this.schemaChangeManager = new SchemaChangeManager(databendSinkConfig);\n                this.preparedStatement = connection.prepareStatement(insertSql);\n                this.preparedStatement.setQueryTimeout(executeTimeoutSec);\n                log.info(\"PreparedStatement created successfully with custom SQL\");\n            } catch (SQLException e) {\n                throw new DatabendConnectorException(\n                        DatabendConnectorErrorCode.SQL_OPERATION_FAILED,\n                        \"Failed to prepare custom statement: \" + e.getMessage(),\n                        e);\n            }\n        } else {\n            try {\n                if (isCdcMode) {\n                    // In CDC mode, we don't create tables here, it's done in AggregatedCommitter\n                    // We'll get the raw table and stream names from the committer via prepareCommit\n                    log.info(\n                            \"CDC mode enabled, table creation will be handled by AggregatedCommitter\");\n                } else {\n                    // Traditional mode\n                    initTraditionalMode(database, table);\n                }\n            } catch (SQLException e) {\n                throw new DatabendConnectorException(\n                        DatabendConnectorErrorCode.SQL_OPERATION_FAILED,","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-databend/src/main/java/org/apache/seatunnel/connectors/seatunnel/databend/sink/DatabendSinkWriter.java#L125-L161","documentation":"Thrown in the DatabendSinkWriter constructor when preparing the user's custom SQL insert statement fails with a SQLException. This happens in the 'custom SQL' branch where the user supplied their own insertSql instead of the auto-generated one.","triggerScenarios":"connection.prepareStatement(customInsertSql) or setQueryTimeout throws: the custom SQL has a syntax error, references non-existent tables/columns, or the query timeout value is invalid (e.g. 0/negative unsupported by the driver).","commonSituations":"User typo in the custom SQL template; custom SQL written for another dialect (MySQL syntax in Databend); schema renamed so the custom SQL references a dropped column.","solutions":["Run the custom SQL directly in a Databend client to reproduce and fix the syntax error.","Verify every table/column referenced in the custom SQL exists in the target database.","Use Databend-compatible syntax; the statement is prepared with parameters (? placeholders), so parameter count must match the SeaTunnelRowType field count.","Check executeTimeoutSec is a positive integer accepted by the JDBC driver."],"exampleFix":"// before\n\"insert into db.tbl values (?, ?, ?)\" // 3 placeholders but schema has 4 fields\n// after\n\"INSERT INTO db.tbl (id, name, ts, amount) VALUES (?, ?, ?, ?)\" // matches row type","handlingStrategy":"validation","validationCode":"// validate custom SQL before configuring the job:\n// run the SQL (with dummy params) in a Databend client: PREPARE stmt FROM 'INSERT ... VALUES (?, ?, ?)';\n// confirm placeholder count == SeaTunnelRowType field count\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Test custom SQL in a Databend client before putting it into config.","Count '?' placeholders and match them to the source schema's column count.","Use Databend-compatible SQL syntax, not MySQL/Postgres dialect.","Keep executeTimeoutSec a positive integer."],"tags":["jdbc","databend","custom-sql","prepared-statement"],"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-23T08:17:48.524Z"}