code: private void cancelHelper(String sql, String mediaType)
    throws SnowflakeSQLException, SFException
    {
      synchronized (this)
      {
        if (isClosed)
        {
          throw new SFException(ErrorCode.INTERNAL_ERROR,
                                "statement already closed");
        }
      }
  
      StmtUtil.StmtInput stmtInput = new StmtUtil.StmtInput();
      stmtInput.setServerUrl(session.getServerUrl())
          .setSql(sql)
          .setMediaType(mediaType)
          .setRequestId(requestId)
          .setSessionToken(session.getSessionToken())
          .setServiceName(session.getServiceName());
  
      StmtUtil.cancel(stmtInput);
  
      synchronized (this)
      {
        /*
         * done with the remote execution of the query. set sequenceId to -1
         * and request id to null so that we don't try to abort it again upon
         * canceling.
         */
        this.sequenceId = -1;
        this.requestId = null;
      }
    }
docs: A helper method to build URL and cancel the SQL for exec
  
  @param sql       sql statement
  @param mediaType media type
  @throws SnowflakeSQLException if failed to cancel the statement
  @throws SFException           if statement is already closed