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 ) ; } }
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 .