Is there some way to prevent a toothache?

The key to preventing toothaches is establishing a regular oral hygiene routine and sticking to it.  For example, failure to brush and floss regularly after meals can significantly increase your risk of developing cavities.  After you eat, bacteria in your mouth feed on on sugar and starch and produce acid that can "eat" a hole (or cavity) in your tooth's enamel.  If the cavity is not filled, it can cause considerable pain and potentially destroy the dentin, pulp and the tooth's nerve.