Some people have problems with stomach acid problems or other digestive issues and sometimes coffee can irritate your stomach.
Caffeine stimulates the central nervous system, which can cause the stomach to produce excess stomach acid and as a result the excess stomach acid that some people experience can gas gastritis and even ulcer formations.
If coffee is making your stomach hurt I would avoid drinking coffee at least for awhile and speak with a doctor about it to get tested for gastritis or other digestive issues.
You might want to try switching to caffeine free coffee and see if the stomach pain goes away and if so then you may only have to drink caffeine free coffee instead of coffee that contains caffeine.