Sometimes it's just pyschological, nervous can make you 'turn soft' easily. If you can get hard on easily but turn soft easily, maybe you were just nervous.
But still, drugs can help in this case to build up your confidence.
Reply to srocco, it's easier to keep hard on when masturbating, doing...