code: public void cancel() throws SQLException {
      checkClose();
      boolean locked = lock.tryLock();
      try {
        if (executing) {
          protocol.cancelCurrentQuery();
        } else if (results != null && results.getFetchSize() != 0 && !results
            .isFullyLoaded(protocol)) {
          try {
            protocol.cancelCurrentQuery();
            skipMoreResults();
          } catch (SQLException e) {
            //eat exception
          }
          results.removeFetchSize();
        }
  
      } catch (SQLException e) {
        logger.error("error cancelling query", e);
        ExceptionMapper.throwException(e, connection, this);
      } finally {
        if (locked) {
          lock.unlock();
        }
      }
    }
docs: Cancels this <code>Statement</code> object if both the DBMS and driver support aborting an SQL
  statement. This method can be used by one thread to cancel a statement that is being executed
  by another thread.
  
  <p>In case there is result-set from this Statement that are still streaming data from server, will
  cancel streaming.</p>
  
  @throws SQLException                    if a database access error occurs or this method is
  called on a closed
  <code>Statement</code>