title: Killing query created by another application
body: <p>I have a Java application where I want to be able to kill queries made to several databases. I know how to get the queries in the information_schema.processlist, but the problem is I don't know how to kill those queries. Usually I would do it using KILL command, but I cant use it in java application (or at least I havent figured out how to do it). </p>
  
  <p>I've been reading about the Statement.cancel but the problem is that the queries are created by another application. I've understood that you have to have Statement variable in the class where you want to cancel it. </p>
  
  <p>if I can use Statement for this purpose, can someone please help me to understand how. I'm using MySQL database. I dont want to set timeout, because I want to be able to kill any query I want to. </p>
  
  <p>These are some examples how I've tried to kill the process:</p>
  
  <pre><code>public synchronized void killProcesses(Set&lt;Long&gt; ids) {
      for (long id : ids) {
          String killCommand="Select 'KILL ' from processlist where id=:id";
  
          Query query= queryManager.createQuery(killCommand);
          query.setParameter("id", id);
          query.getResultList();
      }
  }
  
  public synchronized void killProcesses(Set&lt;Long&gt; ids) {
      for (long id : ids) {
          String killCommand="KILL " + id;
  
          Query query= queryManager.createQuery(killCommand);
          query.getResultList();
      }
  }
  </code></pre>