A major causative factor (75% of gastric and 90% of duodenal ulcers) is chronic inflammation due to Helicobacter pylori, which appears spiral, but is not a spirochaete, rather a bacillus, that colonizes (i.e. settles there after entering the body) the antral mucosa. The immune system is unable to clear the infection, despite the appearance of antibodies. Thus, the bacterium can cause a chronic active gastritis (type B gastritis), resulting in a defect in the regulation of gastrin production by that part of the stomach, and gastrin secretion is increased. Gastrin, in turn, stimulates the production of gastric acid by parietal cells. The acid erodes the mucosa and causes the ulcer.
Another major cause is the use of NSAIDs (see above). The gastric mucosa protects itself from gastric acid with a layer of mucous, the secretion of which is stimulated by certain prostaglandins. NSAIDs block the function of cyclooxygenase 1 (cox-1), which is essential for the production of these prostaglandins. Newer NSAIDs (celecoxib, rofecoxib) only inhibit cox-2, which is less essential in the gastric mucosa, and roughly halve the risk of NSAID-related gastric ulceration.
Thanks to ulcer wiki