Practicing safer sex, such as having one sexual partner and using a condom to protect against STDs, helps prevent STD related bacterial orchitis, while getting immunized against mumps is the best protection against viral mumps-related orchitis.
Attribution: Straight Talk Foundation