code: public void checkMaxAllowedLength(int length) throws MaxAllowedPacketException {
      if (cmdLength + length >= maxAllowedPacket && cmdLength == 0) {
        //launch exception only if no packet has been send.
        throw new MaxAllowedPacketException("query size (" + (cmdLength + length)
            + ") is >= to max_allowed_packet (" + maxAllowedPacket + ")", false);
      }
    }
docs: Count query size. If query size is greater than max_allowed_packet and nothing has been already
  send, throw an exception to avoid having the connection closed.
  
  @param length additional length to query size
  @throws MaxAllowedPacketException if query has not to be send.