{"record":{"id":"6cd403455fb824d4","repo":"pentaho/pentaho-kettle","slug":"error-cancelling-statement","errorCode":null,"errorMessage":"Error cancelling statement","messagePattern":"Error cancelling statement","errorType":"exception","errorClass":"KettleDatabaseException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/pentaho/di/core/database/Database.java","lineNumber":1044,"sourceCode":"    cancelStatement( selStmt );\n  }\n\n  /**\n   * Cancel an open/running SQL statement\n   *\n   * @param statement the statement to cancel\n   * @throws KettleDatabaseException\n   */\n  public void cancelStatement( Statement statement ) throws KettleDatabaseException {\n    try {\n      if ( statement != null ) {\n        statement.cancel();\n      }\n      if ( log.isDebug() ) {\n        log.logDebug( \"Statement canceled!\" );\n      }\n    } catch ( SQLException ex ) {\n      throw new KettleDatabaseException( \"Error cancelling statement\", ex );\n    }\n  }\n\n  /**\n   * Specify after how many rows a commit needs to occur when inserting or updating values.\n   *\n   * @param commitSize The number of rows to wait before doing a commit on the connection.\n   */\n  public void setCommit( int commitSize ) {\n    setCommitSize( commitSize );\n    setAutoCommit();\n  }\n\n  public void setAutoCommit() {\n    String onOff = ( commitsize <= 0 ? \"on\" : \"off\" );\n    try {\n      connection.setAutoCommit( commitsize <= 0 );\n      if ( log.isDetailed() ) {","sourceCodeStart":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/database/Database.java#L1026-L1062","documentation":"KettleDatabaseException thrown by Database.cancelQuery() when Statement.cancel() throws a SQLException. Cancel is usually called to abort a running query from another thread; failure means the driver could not cancel (statement already finished/closed, driver lacks async cancel support, or connection is broken).","triggerScenarios":"Calling Database.cancelQuery() while statement.cancel() throws — statement already completed, connection dead, or driver does not support cancellation (e.g. some drivers throw SQLFeatureNotSupported).","commonSituations":"Cancelling a long-running transformation step whose query already returned, cancelling after the connection timed out, drivers without true async cancel (MySQL needs a separate connection to kill the query).","solutions":["Check the wrapped SQLException for feature-not-supported — the driver may not support cancel; use DB-specific KILL QUERY/session commands instead","Verify the connection is still alive; a dead connection cannot cancel anything","Ignore/tolerate this error when it races with statement completion (cancel after finish is harmless)","Upgrade the driver to one supporting statement cancellation"],"exampleFix":"// before\ntry { database.cancelQuery(); } catch (Exception e) { throw e; }\n// after\ntry {\n  database.cancelQuery();\n} catch (KettleDatabaseException e) {\n  log.debug(\"Cancel failed (query may already have finished): \" + e.getMessage());\n}","handlingStrategy":"try-catch","validationCode":"if ( database.getConnection() == null || database.getConnection().isClosed() ) {\n  return; // nothing to cancel\n}","typeGuard":null,"tryCatchPattern":"try {\n  database.cancelQuery();\n} catch ( KettleDatabaseException e ) {\n  log.debug( \"Cancel raced with completion or unsupported: \" + e.getMessage() );\n}","preventionTips":["Treat cancel failures during shutdown as benign","Use a driver that supports Statement.cancel (or DB-level KILL QUERY)","Avoid cancelling after the statement future already completed","Keep the cancelling reference on the same thread-safe Database object"],"tags":["jdbc","database","statement","cancel"],"backgroundTag":"database-query-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}