Listen to why David prayed to God,
“I have called upon You, for You will hear me, O God; incline Your ear to me, and hear my speech” (Psalms 17:6).
David knew that he could depend upon God, and that God would be favorable to the prayer. Therefore, David asked God boldly for help,
“Show Your marvelous lovingkindness by Your right hand, O You who save those who trust in You from those who rise up against them. Keep me as the apple of Your eye; hide me under the shadow of Your wings, from the wicked who oppress me, from my deadly enemies who surround me” (Psalms 17:7-9).
The psalms of David and the story of this man, who had a heart like God’s, in First and Second Samuel, show that God answered such prayers.