"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?" (2 Samuel 12:22)
Part of the consequences of King David's adultery with the wife of another man was the death of the child their liaison produced. The prophet, Nathan, pronounced God's judgment in no uncertain terms, yet David went immediately to prayer, asking God to spare the life of his child. After the death, David's explanation for his seemingly futile petitions to God was simply, "It doesn't hurt to ask. Who knows, maybe God would change His mind." Certainly, David had precedent. God had done just that, when Moses petitioned Him on behalf of Israel.
I learn several things from this story, and the most important one, I think, is this: God is more interested in our communication than my request. Faith is believing in God's integrity (Heb.11:6) not His generosity. Answered prayers may encourage my faith, but (seemingly) unanswered ones deepen my Christian walk. When I can say, like Job, "Though he slay me, yet will I trust him" (Job 13:15); God can say, as He did to Abraham, "Now I know that thou fearest God" (Gen.22:12).
We often say of a parent who gives his or her child anything he or she asks for, "That's not really love. Real love does what is best, not always what is asked." As a matter of fact, David had another son on whom he lavished this kind of harmful love, and it ruined both the boy and his sister (1Kings 1). Are we to think God is such a parent? I think not. God always does what is best for His children.
Another obvious lesson from this story is that prayer is always profitable, to answer the question in Job (21:15), even when it seems futile. To pray for a wayward son or daughter, even though we know the disposition and consequences of their lives lie solely at their doorstep, would seem to be a waste of time. Yet as the words of David indicate, where there's life, there's hope; and as he says, "Who can tell whether God will be gracious to [us]?" And in the meantime, we are learning the blessedness of trusting in the good hand of our God. We know that David's unanswered petition did not leave him bitter, because he was able to comfort his wife, the child's mother, during this trying time in their lives.
Prayer may not always get that for which is asks, but it always gets the attention of the Father; and for the child who loves the Father more than the answer, that will be enough.