David ultimately confessed and repented of his great sin. But there are painful consequences that follow even our confessed sin. that's why we need to avoid sin in the first place. David's sin with Bathsheba and the murder of Uriah cost him a huge price.
...It cost him dearly when his infant son died.
...It cost him dearly when his oldest son, Amnon, raped his half-sister and David's daughter Tamer.
...It cost him dearly when his son Absalom killed brother Amnon to avenge the rape of Tamar.
...it cost him dearly when years later, his trusted friend and counsellor, Ahithophel, assisted young Absalom in a plot to overthrow David and rip the kingdom out of his hands.
Some sin looks particularly attractive, remember the consequences of sin that haunted David for the rest of his life. whatever that specific sin is, it's not worth it. You can take this to the bank: no matter how alluring the sin looks like right now, it will wind up costing you more than you are willing to pay.