I heard the most fascinating lesson about the affair of David and Bathsheba. David did not sin with her due to lust.
His sin was idleness. He was supposed to be leading war with his troops, which as king he was required to do in times of war. Instead, he stayed behind and lounged in his palace. Thus, his idleness stirred the fire of lust inside him.
The Bible openly condemns idleness. It’s briefly sweet, but it brings suffering and hunger. That’s what happened to David. His idleness led to an affair which led to murder. As a result God took away his son.
Idleness leads to other sins, which will make you suffer. So, find a hobby and keep you hands busy. It will keep your mind off of evil things.
2 Samuel 11:1-4: "In the spring of the year,[a] when kings normally go out to war, David sent Joab and the Israelite army to fight the Ammonites. They destroyed the Ammonite army and laid siege to the city of Rabbah. However, David stayed behind in Jerusalem. Late one afternoon, after his midday rest, David got out of bed and was walking on the roof of the palace. As he looked out over the city, he noticed a woman of unusual beauty taking a bath. He sent someone to find out who she was, and he was told, “She is Bathsheba, the daughter of Eliam and the wife of Uriah the Hittite.” Then David sent messengers to get her; and when she came to the palace, he slept with her." (NLT)