I was looking for the answer to this question this morning, and this is what I found on wisegeek.com :
"There are a number of reasons why the level of hydrochloric acid rises and causes a stomachache of this type. Many of these underlying causes have to do with lifestyle choices. This means it is possible to alter habits and behavior and minimize the recurrence of sour stomach in many cases.
One of the most common causes of this phenomenon has to do with consuming too much food within a couple of hours of retiring for the evening. Many people who choose to eat late in the evening do not allow enough time for their bodies to process the food before positioning themselves in a prone position. This makes it easier for the acid to back into the digestive tract and cause a burning sensation that makes it very difficult to rest. The obvious solution here is to eat earlier in the evening and engage in some light activity, such as walking to help stimulate the digestive process.
Along with consuming too much food too late in the day, the type of food consumed can also lead to a sour stomach. Excess consumption of fatty foods can irritate the stomach and lead to a great deal of pain. While taking an antacid may help ease the discomfort, a better option is to consume less animal fats and consume more nutrient-rich options, such as green vegetables.
The root cause for sour stomach in some cases has nothing to do with the type or amount of food consumed. Instead, the stomach is irritated by the consumption of substances that could be minimized or avoided altogether. Smokers increase their chances of developing a sour stomach. In addition, tobacco consumption can exacerbate any tendency to develop an ulcer. Choosing to quit smoking and avoid the use of tobacco products in general can save the individual a lot of pain and also minimize the chances of developing a peptic ulcer.
Stress can also be involved in the creation of a sour stomach. The emotional state of an individual will often impact the ability of various systems in the body to perform at peak efficiency. Someone who is constantly worried or fearful often find they experience a tightness in the stomach area that leads to indigestion no matter what or when they eat. Often, counseling or engaging in activities to minimize stress levels will also lead to a decrease in problems with indigestion as well. "