Another interpretation of "Bikrei Anani" (a phrase from the beginning of Psalm 18): There were three things that troubled David, but God comforted him. The first was the destruction of the Temple. As it says (Psalm 132:1), "Remember, O Lord, for David all his hardships." And God comforted him by revealing to him the place where the Temple would be built, as it says (1 Chronicles 22:1), "Then David said, 'This is the house of the Lord God.'"
The second thing that troubled David was the sin with Bathsheba. The people of Israel were saying that David deserved to die for what he had done. But God comforted him by saying (2 Samuel 12:13), "The Lord has taken away your sin. You will not die."
The third thing that troubled David was the question of who would succeed him as king. God comforted him by promising that his son Solomon would be his successor, as it says (1 Chronicles 22:9-10), "Behold, a son will be born to you...and his name shall be Solomon...I will establish his kingdom forever." And when David asked, "Who will be born to me?" God replied, "Through whom will you be healed of your sins?
Through the son of the woman with whom you sinned." This was revealed to David by the prophet Nathan, as it says (2 Samuel 12:25), "And he sent word through Nathan the prophet, and he named him Jedidiah."