David pleaded with God for the boy. He fasted, went [home], and spent the night lying on the ground.
References for 2 Samuel 12:16
The elders of his house stood beside him to get him up from the ground, but he was unwilling and would not eat anything with them.
On the seventh day the baby died. But David's servants were afraid to tell him the baby was dead. They said, "Look, while the baby was alive, we spoke to him, and he wouldn't listen to us. So how can we tell him the baby is dead? He may do something desperate."
When David saw that his servants were whispering to each other, he guessed that the baby was dead. So he asked his servants, "Is the baby dead?" "He is dead," they replied.
Then David got up from the ground. He washed, anointed himself, changed his clothes, went to the Lord's house, and worshiped. Then he went home and requested [something to eat]. So they served him food, and he ate.
His servants asked him, "What did you just do? While the baby was alive, you fasted and wept, but when he died, you got up and ate food."
He answered, "While the baby was alive, I fasted and wept because I thought, 'Who knows? The Lord may be gracious to me and let him live.'
But now that he is dead, why should I fast? Can I bring him back again? I'll go to him, but he will never return to me."