I was also thinking a urinary tract infection. I certainly hope it's that and not bladder cancer...but either way, he needs to be seen by a vet.
I hope everything turns out OK and that he feels better soon!
He may have a UTI or it could be worse - bladder cancer. Please get him to a vet