No and Yes
No you can not prevent ulcers.
Mouth ulcers are related to the immune system. It has not been proven by science, but they say that the development of the ulcers are linked to the immune system.
Personally, i believe its a combination of bacterial and viral. I have seen people control the mouth ulcers when it first develops with antibacterial mouthrinse listerine (the purple or green bottle).