19 But when David saw that his servants were talking together quietly, he was certain that the child was dead: and he said to his servants, Is the child dead? and they said, He is. 20 Then David got up from the earth, and after washing and rubbing himself with oil and changing his clothing, he went into the house of the Lord and gave worship: then he went back to his house, and at his order they put food before him and he had a meal. 21 Then his servants said to him, Why have you been acting in this way? you were weeping and going without food while the child was still living; but when the child was dead, you got up and had a meal. 22 And he said, While the child was still living I went without food and gave myself up to weeping: for I said, Who is able to say that the Lord will not have mercy on me and give the child life? 23 But now that the child is dead there is no reason for me to go without food; am I able to make him come back to life? I will go to him, but he will never come back to me. 24 And David gave comfort to his wife Bath-sheba, and he went in to her and had connection with her: and she had a son to whom she gave the name Solomon. And he was dear to the Lord.
Matthew Henry's Commentary on 2 Samuel 12:19-24
Commentary on 2 Samuel 12:15-25
(Read 2 Samuel 12:15-25)
David now penned the 51st Psalm, in which, though he had been assured that his sin was pardoned, he prays earnestly for pardon, and greatly laments his sin. He was willing to bear the shame of it, to have it ever before him, to be continually upbraided with it. God gives us leave to be earnest with him in prayer for particular blessings, from trust in his power and general mercy, though we have no particular promise to build upon. David patiently submitted to the will of God in the death of one child, and God made up the loss to his advantage, in the birth of another. The way to have creature comforts continued or restored, or the loss made up some other way, is cheerfully to resign them to God. God, by his grace, particularly owned and favoured that son, and ordered him to be called Jedidiah, Beloved of the Lord. Our prayers for our children are graciously and as fully answered when some of them die in their infancy, for they are well taken care of, and when others live, "beloved of the Lord."