2 Samuel 12:24
And David comforted Bath-sheba his wife, and went in unto her, and lay with her: and she bare a son, and he called his name Solomon: and the LORD loved him. And David comforted Bath-sheba his wife, and went in unto her, and lay with her: and she bare a son, and he called his name Solomon: and the LORD loved him.
David had Uriah himself carry his own death order to Joab, directing that Uriah be placed at the front of the fiercest fighting and then abandoned by withdrawal so that he would be struck down and die, and Joab carried out the order so that Uriah fell by the sword of the Ammonites. Joab then carefully arranged the battle report so as to implicate neither himself nor the king, instructing the messenger that if the king grew angry over the losses he was to answer that anger by also reporting the death of Uriah, and David responded by treating the loss as the common fortune of battle in which the sword devours one as well as another, urging Joab to press the attack against the city, overthrow it, and take courage. The account is that of David departing from God and yielding to Satan while still holding the position and authority God had given him, using that authority to command the killing of Uriah contrary to God's law, and of Joab breaking God's law because the king commanded it, showing that God-given power is to be used only in harmony with divine law so that obedience becomes sin when a ruler commands disobedience to God. That departure from God's teaching brought disgrace on his reputation and brought a day of reckoning, illustrating that keeping God's word before him had made him steadfast while forsaking it led him astray.
The verse records that after David comforted Bath-sheba his wife Solomon was born, that the Lord loved him, that his life began under divine favor, and that the additional name Jedidiah was given as a sign of that love. He is identified as the beloved of the Lord, with the name Jedidiah given to him meaning beloved of the Lord. He was honored as beloved of God, and his early character was pure and elevated and marked by exceptional piety and wisdom. Loved by God, he entered his reign as a young man favored by God with high promise of prosperity and honor.
He was a son whom the Lord loved and who was chosen to build the temple, yet he departed from the Lord's way by marrying heathen women contrary to the law and was led by them into idolatry. Entrusted with the great work of building the temple, he later formed alliances with idolatrous nations and married heathen women whose influence led him in his later years to forsake God's temple and worship their idols. Beloved of God, he later formed alliances with idolatrous nations and through his marriages to heathen women was led in his later years to turn from God's temple and prepare places for their idols. Divine favor did not make him dependable, for despite being beloved by God and entrusted with building the temple he later allied himself with idolatrous nations, married women raised in heathen worship, and built places for their idols.