What is the safest and most effective way to have sex and avoid an std?

Monogamy. Use a condom while in a monogamous relationship with someone you trust who has been previously tested.
Self masturbation. Thats pretty much it. If you have sexual contact with someone else, then you are at risk. Yes oral sex may be less risky for some things, like hiv, but for others like gonorrhea or hpv its still risky. Practice safe sex (condoms, etc.) always (even with oral sex) and keep safe and get tested frequently!