Preventive measures include maintaining good hygiene, staying hydrated, and practicing safe sex to reduce the risk of sexually transmitted infections. Regular medical check-ups and early treatment of urinary tract infections can also help prevent prostatitis.