I suspect prostatitis, or inflammation/infection of an enlarged prostate, common in unneutered male dogs
. Other possiblities include kidney
infection, kidney or bladder stones, or cancer of the prostate or bladder. I recommend urine testing and culture for infection, rectal examination to palpate the prostate, and possible xrays or ultrasound of the prostate, bladder and kidneys. If prostatitis is diagnosed, it is treated with a several week course of oral antibiotics and neutering.