
Many times the sages explicate Biblical stories to present practical messages for their times. Thus, for example, they wanted to state that a person should not tempt himself but bypass temptation, and so they said: When King David saw that his name is not mentioned in prayers alongside the forefathers, that the text of the prayers read “Lord of Abraham, Lord of Isaac, Lord of Jacob” and “Lord of David” was not mentioned, he begged G-d that he name be mentioned. G-d told him that he was missing from the list of founders of the nation because he never stood up to a test as they had, and so his greatness was less than theirs. David asked G-d to test him as well. G-d agreed to David’s request and even revealed how he would be tested: sex. David, who wished to pass the test, had sex with his wives in the morning. He thought this would keep him from being tempted by other women later in the day and make him fail G-d’s test. We learn of this habit from the verse “Then it happened one evening that David arose from his bed and walked on the roof of the king’s house” (II Samuel 11:2). The words arose from his bed are interpreted to mean that David changed his sleeping habits — instead of having sex at night he would have sex in the morning. One of the sages, Rabbi Judah, said that David’s method of calming his desires by having sex in the mornings contradicted the sages’ ruling that men’s sexual urges work the opposite way: the less one has sex the less desire one has and the more sex one has, the more desire. “A man has a small organ. When it is satisfied it is hungry and when it is starved it is satisfied.” One day, while David was walking on the roof, Bathsheva was modestly washing her hair behind a beehive box. Satan pushed the box over and Bathsheva was revealed to the eyes of David. Immediately his desire burned bright and he sent for Bathsheva and had sex with her, as is written, “Then David sent messengers, and took her; and she came to him, and he lay with her” (II Samuel 11:4). Therefore a person should never put himself in temptation’s path, for David, King of Israel, placed himself before a test and failed.
(Babylonian Talmud, Tractate Sanhedrin 107a)