Welcome to e health forum.
Yes, it is possible that stress or sexual tension may be the probable cause. Usually proper rest and relaxation and stress management should help you get over such issues. Since this is a physiological and normal event, it does not need any medications.
In case, you are worried that you will get an erection during a class, masturbating early morning, before you go to work should help relieve such issues.