problem with servo

As soon as I connect the servo, either it keeps on rotating continuously or the Arduino gets disconnected from the computer.

If the servo in the second picture is your servo, it probably requires more power than the arduino can supply to it. You probably need an external power supply for your servo.