Urinary tract infection

How do you get uti's?  Are they from having sex?