How do I get over a fear of pain during sex?

My boyfriend and I have a terrible sex life after three years of dating, and I don't know what to do. I have this lingering fear of pain during sex after having two partners previously who weren't careful. How can I stop projecting this onto my current boyfriend?