When we were during attention at Psychology class (another 2016/2017 winter semester course that I took), we also touched on the subject of attention. Because the attention is limited, the best way of dealing with pain would be to start doing things, that require a lot of attention. One of the examples, that was given, was math. And here I mean the math by hand type of things, since (at least for me) this requires a lot more attention than programming the solution on the computer.
I know, that when I am at the dentist office, I generally start creating fanfiction stories in my head, so I don't need to think about the pain. This works for me. I guess reciting songs a person knows by heart would also help.
This strategy can also be used with non-physical pain or with any affective state, that needs attention. Like anger or frustration or something else. Sure, it is hard to stop putting attention on the situation, that one is in, but as soon as being removed from it, putting the attention on something else can help with the feelings.
I guess, this is one way the meditation can help people, since meditation is (also) training of the attention. But I am sure, that even without it, simply putting it on something else, when necessary, can still be helpful.