I'm not sure which son you meant of David. But when the first child that David had with Bathsheeba died, the following happened.
[2 Samuel 12:19-20]
19 But when David saw that his servants whispered, David perceived that the child was dead: therefore David said unto his servants, Is the child dead? And they said, He is dead.
20 Then David arose from the earth, and washed, and anointed himself, and changed his apparel, and came into the house of the Lord, and worshipped: then he came to his own house; and when he required, they set bread before him, and he did eat.
David have learned one thing, to worship God in all things. This is very difficult to do, but whatever you have lost, God is able to restore. Maybe in ways we do not know of. I believe that.
Out of that worship, in verse 24, David went again and comforted Bathsheeba and out of this worship, they got their second son Solomon, who later became the wisest man in the Old Testament.
Many times I go through very difficult times and losses and sometimes I don't understand them but I know this, my God will always restore and He never fails me. I just need to learn to see things the way He sees them.
Learn to encourage yourself in the Lord... His name is Comforter...