Did he teach special ways to handle those sexual lusts, did he prohibit it, or just not paying any attention to it? If so what were they?
he didn't prohibit it for secular people, it's not even subsumed under sexual misconduct
but since it's a lustful urge and act it is unwholesome and unskillful, and those need to be handled using the Right effort
[i]"There is the case where a monk generates desire, endeavors, activates persistence, upholds & exerts his intent for the sake of the non-arising of evil, unskillful qualities that have not yet arisen.
[ii] "He generates desire, endeavors, activates persistence, upholds & exerts his intent for the sake of the abandonment of evil, unskillful qualities that have arisen.
[iii] "He generates desire, endeavors, activates persistence, upholds & exerts his intent for the sake of the arising of skillful qualities that have not yet arisen.
[iv] "He generates desire, endeavors, activates persistence, upholds & exerts his intent for the maintenance, non-confusion, increase, plenitude, development, & culmination of skillful qualities that have arisen: This, monks, is called right effort."
Maggavibhanga Sutta (SN 45.8)
avoid situations and sensory stimuli which may provoke sexual desire, at that guarding of the sense doors is helpful
when and if it still arises think of the drawbacks which giving in to the urge may bring, contemplate its impermanence, develop understanding that it's going to eventually subside anyway, so that it loses a degree of its attractiveness and immediacy
I think this will be helpful: Ask A Monk: Pornography and Masturbation (and Addiction in General)
Here is a summary what's said in the video (heavily paraphrased):
The first way to overcome an addiction is re-evaluate it: the Buddha started his talk on DO with 'ignorance'; it's not addiction that's the problem, why do we crave? It's because of ignorance, i.e. misunderstanding the object of our desires. It's not that we have to cut something out, what we have to do is see the object clearly. We're addicted because we don't understand (if we did understand then we wouldn't cling).
Your thinking that it's a problem means that you don't want to think about it. Instead of not thinking about it, you need to see it clearly.
If you practice meditation then you'll see that DO shows a path out of addiction.
We're craving a sense-object (e.g. something that we see). That produces a (pleasant) sensation. The sensation creates a desire. So you desire to see it again i.e. a clinging. Deciding that's good and repeating the sense-experience strengthens the clinging: it wires the brain.
There's no intrinsic connection between nakedness and desire.
When we were children we saw naked people without desire. It's the repeated connection (repeated sexual act) that causes attachment. Cows and fishes have a body like ours but we're not attracted to them, it's our repeated action which cause us to be "reborn" with these desires.
To get out of it, we need wisdom to see it as it is.
One way is to examine / analyze the human body, i.e. the object of the sense-experience: e.g. take it apart and don't mis-perceive it as something desirable ... so even if we're attached to pleasant sensations we don't associate those feelings with the senses (e.g. the sight of a naked body). We stop seeing the body is beautiful, e.g. hair is greasy etc., teeth bleed etc., nothing about the body is beautiful.
In ultimate reality you just see, without seeing it as hair, it's just light touching the eye. So note it as "seeing, seeing" not as "hair".
So that's one thing: change the connection between seeing and sensation (i.e. between the sense and the feeling).
The next thing you can change is the connection between the feeling and the craving. What benefit do you gain from pleasure? You might say "pleasure is good" which is a tautology. Buddhism says that if something is beneficial you should do that. So you have to decide whether masturbation and/or the feeling of pleasure is beneficial.
The third step is the desire. You're more likely to feel guilty about the desire than about the feeling. Desire is a tension, a stress ... and not worthwhile. It's not evil but it's stressful. Wanting something implies unease.
In summary, reinvestigate:
- The object of the desire
- The feeling (sensation)
- The desire itself
Sometimes people (perhaps especially religious people) see sex as a high human state; but sex isn't the highest human state. And Buddhism lets you rise above the human state, the negative states.
If you are looking for ways to be free from lust...check out an earlier question...Lust - How Can It Be Overcome?
In the Potaliya Sutta, the Buddha admonishes a householder (albeit a different kind), about sensual lust and compares it to bare bones, a lump of flesh, a torch of straw, a pit of burning coal, a dream, borrowed goods, a fruit tree, a slaughter house, a stake of swords or a snake's head.
In the Puttamansa Sutta, the Buddha talks about three kinds of nutriments - edible food, sense impression and volitional thought. If one is bent on overcoming craving in general and lust in particular, one must be mindful of how we use these nutriments. Food must be consumed mindfully and over-consumption should be avoided. In this age of internet, various media and websites are constantly affecting our senses and volitional thoughts. One must be mindful what we consume on internet.
In the Vitakkasanthana Sutta, Buddha suggests 5 strategies to overcome mind of any unwholesome thoughts. These are:
- He should attend to another theme, apart from that one, connected with what is skillful
- (Then, if evil thoughts still arise) he should scrutinize the drawbacks of those thoughts
- (Then, if evil thoughts still arise) he should pay no mind and pay no attention to those thoughts
- (Then, ...) he should attend to the relaxing of thought-fabrication with regard to those thoughts
- (Then, ...) with his teeth clenched and his tongue pressed against the roof of his mouth — he should beat down, constrain, and crush his mind with his awareness
Also in Bhikkhuni Sutta, Ven Ananda admonishes a Bhikkhuni about sensual lust. He argues
'This body comes into being through craving. And yet it is by relying on craving that craving is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk hears, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now.' The thought occurs to him, 'I hope that I, too, will — through the ending of the fermentations — enter & remain in the fermentation-free awareness-release & discernment-release, having known & realized them for myself in the here & now.' Then he eventually abandons craving, having relied on craving. 'This body comes into being through craving. And yet it is by relying on craving that craving is to be abandoned.' Thus was it said. And in reference to this was it said.
'This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said. And in reference to what was it said? There is the case, sister, where a monk hears, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now.' The thought occurs to him, 'The monk named such-and-such, they say, through the ending of the fermentations, has entered & remains in the fermentation-free awareness-release & discernment-release, having known & realized them for himself in the here & now. Then why not me?' Then he eventually abandons conceit, having relied on conceit. 'This body comes into being through conceit. And yet it is by relying on conceit that conceit is to be abandoned.' Thus was it said, and in reference to this was it said.
This body comes into being through sexual intercourse. Sexual intercourse is to be abandoned. With regard to sexual intercourse, the Buddha declares the cutting off of the bridge.
The above answer contains a mix of Suttas addressed to lay people and to monks. As already pointed out in other answers, for lay people, Buddha advised refraining from sexual misconduct. But there are examples from Buddha's period of lay people living celibate life and reaching upto the Anagami stage. So pick and choose from the above sources.
Also I would like to add that Insight Meditation or Vipassana will help one greatly on this path. If one wishes to undertake a retreat to learn Vipassana, Ven S. N. Goenka's retreats would be a great place to start. And if one already practices Vipassana, it is important to preserve the regular practice without letting the feelings of guilt or anger overcoming us.
It's a bodily function. Let's remove the stigma and modernize our thoughts. You lose most of that motivation when you get older anyway. As a young man, or woman, just don't let it control you. When it's necessary then do it. To pay it such heed is to give the desire more power. Don't consider it some moral victory if you dont or some moral dilemma if you do.
Not to minimize the impact they intended with their selfless action - but I liken this to the approach taken by the Dalai Lama recently when asked about self-immolation incidents. He wisely acknowledged that any position he took would seem either intolerable or heartless. So he chose silence. Sakyamuni would not turn down meat when offered as alms, but he did not seek animals to be killed for him. Sometimes it's important to know when to say or do nothing. I'd say wu wei.
The first sanghadisesa rule explains it for monks.
It's important that lay Buddhists keep the Uposatha practice, or at least once a week avoid all sexual activity, including masturbation. Sakka Sutta: To the Sakyans (on the Uposatha) AN 10.46