{"record":{"id":"409f881e33ac7777","repo":"prestodb/presto","slug":"jdbc-error-409f88","errorCode":"JDBC_ERROR","errorMessage":"Failed to execute query. ${e.message}","messagePattern":"Failed to execute query\\. (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/procedure/ExecuteProcedure.java","lineNumber":73,"sourceCode":"\n    public void execute(ConnectorSession session, String query)\n    {\n        try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(getClass().getClassLoader())) {\n            doExecute(session, query);\n        }\n    }\n\n    private void doExecute(ConnectorSession session, String query)\n    {\n        try (Connection connection = jdbcClient.getConnection(session, JdbcIdentity.from(session), (JdbcSplit) null)) {\n            connection.setReadOnly(false);\n            try (Statement statement = connection.createStatement()) {\n                //noinspection SqlSourceToSinkFlow\n                statement.executeUpdate(query);\n            }\n        }\n        catch (SQLException e) {\n            throw new PrestoException(JDBC_ERROR, \"Failed to execute query. \" + firstNonNull(e.getMessage(), e), e);\n        }\n    }\n\n    @Override\n    public Procedure get()\n    {\n        return new Procedure(\n                \"system\",\n                \"execute\",\n                ImmutableList.of(new Argument(\"QUERY\", VARCHAR)),\n                EXECUTE.bindTo(this));\n    }\n}\n","sourceCodeStart":55,"sourceCodeEnd":87,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/procedure/ExecuteProcedure.java#L55-L87","documentation":"ExecuteProcedure's EXECUTE procedure runs an arbitrary SQL statement (typically DDL/DML like TRUNCATE or COMMENT) directly on the underlying database connection via statement.executeUpdate. If the database throws a SQLException, it is rethrown as a PrestoException with code JDBC_ERROR and the database's own message. This indicates the remote database rejected the query.","triggerScenarios":"Invoking system.procedure execute(query => '...') on a JDBC catalog where the query is invalid SQL for the target DB, lacks privileges, references missing objects, violates constraints, or the connection is in a bad state.","commonSituations":"Typing Presto/MySQL-flavored syntax for a different backend DB; executing DDL without DBA privileges; TRUNCATE on a table with foreign keys; quoting/identifier differences between Presto and the underlying database.","solutions":["Read the wrapped SQLException message (the cause) to get the database-specific reason","Run the query directly in the target database's client to confirm and fix syntax","Check the connected user's privileges for the operation (DDL, TRUNCATE, etc.)","Qualify table/schema names the way the underlying database expects and use its dialect's syntax"],"exampleFix":"// before\nCALL jdbc.system.execute_query('TRUNCATE TABLE mytable');\n// after (fully qualified, DB-correct syntax and adequate privileges)\nCALL jdbc.system.execute_query('TRUNCATE TABLE my_schema.my_table');","handlingStrategy":"try-catch","validationCode":"// Validate the SQL before executing via the procedure:\n// ensure statement is one the backend DB supports, e.g.\nString q = query.trim().toLowerCase();\nif (q.contains(\"/*presto-only\") || !isKnownBackendStatement(q)) {\n    throw new IllegalArgumentException(\"Query may not be valid for the underlying database dialect\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    CALL jdbc.system.execute(query => :sql);\n} catch (PrestoException e) {\n    if (\"JDBC_ERROR\".equals(e.getErrorCode().getName())) {\n        Throwable cause = e.getCause(); // SQLException from backend; log cause.getMessage() for DB-specific detail\n    } else {\n        throw e;\n    }\n}","preventionTips":["Test the statement in the target database's native client before running via EXECUTE","Use the backend database's SQL dialect and fully qualified identifiers","Verify the connected user has the required privileges for DDL/TRUNCATE","Read the exception's cause chain — the real database error message is in the cause"],"tags":["jdbc","sql","database-error","procedure"],"backgroundTag":"sql-execution-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}