A urinary tract infection or, much more likely, a non-bacterial inflammation
or irritation of the prostate would be a common cause of pain or discomfort
associated with urinary symptoms and changes in erection
You are also at the age where many other factors, including age, begin to affect the ability to obtain and maintain an adequate erection. Recommend you see a urologist to evaluate.