You cannot so easily prevent a spark from occurring when connecting a battery, but you can minimize it! If you want the smallest possible spark, then you will need to disconnect all the components in the car that are drawing electrical power. As fewer components are trying to draw power from the battery, the sparks will get smaller.