And he said, While the child was yet alive, I fasted and wept: for I said, Who can tell whether GOD will be gracious to me, that the child may live? Who can tell - David, and indeed all others under the Mosaic dispensation, were so satisfied that all God's threatenings and promises were conditional, that even in the most positive assertions relative to judgments, etc., they sought for a change of purpose. And notwithstanding the positive declaration of Nathan, relative to the death of the child, David sought for its life, not knowing but that might depend on some unexpressed condition, such as earnest prayer, fasting, humiliation, etc., and in these he continued while there was hope. When the child died, he ceased to grieve, as he now saw that this must be fruitless. This appears to be the sole reason of David's importunity.
Related Commentaries of 2 Samuel 12:22
2 Samuel 12:22
22 And he said, While the child was yet alive, I fasted and wept: for I said, Who can tell whether GOD will be gracious to me, that the child may live?