An ulcer is simply a breakage in the continuity of a membrane lining. Therefore you can have skin ulcers, oral ulcers etc. However usually when someone talks about ulcers unless they are medical people, they are almost always talking about ulcers in the stomach. The medical term is peptic ulcer disease.
Peptic ulcers are as a result of an infection by a bacteria known by a difficult name (Helicobacter pylori). This bacteria have an effect on the stomach walls that remove a coat of mucus that usually protects the stomach from erosion by gastric acid. The acid is produced to breakdown food. Gastric acid is so strong that it can erode the stomach wall and then cause an ulcer.
Stress CANNOT cause ulcers. Initially it was thought that stress caused ulcers. However it is now clear that infection by H. pylori bacteria is the cause of ulcers.
However if you are stressed and not eating, then the acid produced will not find any food to breakdown and that is where the thinking that stress causes ulcers came from.