Thank you for asking. I can understand your concern. Stress is an important factor for not having erections. Exam stress is an important factor in your case. About spontaneous erections, your body and mind needs to be in a extremely relaxed state to have a spontaneous erections, although it is not a parameter to assess for Erectile Dysfunction. Your masturbation habit and technique is not proper. You must learn a proper healthy technique from a qualified expert. Use of pornography, can damage you future sex life. Also you must have a correct knowledge and concept regarding sex.
Next Steps
I would strongly suggest to to have a detailed consultation with a sexologist. You can ask a detailed query here on practo or visit one nearby you.