Yes, they can. My last long term relationship was very stressful in the regard, due to the fact that I was a first year in veterinary school and my SO was an engineer working on his PhD. My dog has always been a comfort to me, in many times like that.
But there here is a caveat and some other advice.
I would first look at expanding a social network of *human* friends 😉 I'm sure you've heard this before, but getting a dog is a very large life change. Not as much as a child or course, but you will be tied down in many ways and will have to re-schedule your life to accommodate the dog. You don't have to do that as much with friends. Plus, as much as we love animals, they cannot replace human-human social interaction which is necessary for proper mental health.
I wholeheartedly agree with dogs being wonderful companions that can get you through rough times. Just think very hard about *why* you are getting the dog. If it is to fill an emotional gap….well, just be careful and think things through. I'm certainly not trying to accuse or discourage (since I know nothing of your other reasons for wanting a dog besides what you posted, I can't make a real judgement), just giving my 2 cents 