The foundation of David's plea is God's character. He begins and ends this prayer by describing the LORD as the One who is merciful, faithful, righteous and steadfast in love. In verse two, David acknowledges his inability to stand before God in judgment. No one can! But still, he cries to the LORD in his despair expecting an answer.
The situation David finds himself in, and the honesty of his prayer reminds me of a prayer from The Valley Of Vision:
The Broken Heart
No day of my life has passed that has not proved me guilty in thy sight.
Prayers have been uttered from a prayerless heart;
Praise has been often praiseless sound;
My best services are filthy rags.
Blessed Jesus, let me find a covert in thy appeasing wounds.
Though my sins rise to heaven thy merits soar above them;
Though unrighteousness weights me down to hell,
thy righteousness exalts me to thy throne.
All things in me call for my rejection,
All things in thee plead my acceptance.
I appeal from the throne of perfect justice to thy throne of boundless grace.
Grant me to hear thy voice assuring me:
that by thy stripes I am healed,
that thou wast bruised for my iniquities,
that thou hast been made sin for me
that I might be righteous in thee,
that my grievous sins, my manifold sins, are all forgiven,
buried in the ocean of thy concealing blood.
I am guilty, but pardoned,
lost, but saved,
wandering, but found,
sinning, but cleansed.
Give me perpetual broken-heartedness,
Keep me always clinging to thy cross,
Flood me every moment with descending grace,
Open to me the springs of divine knowledge,
sparkling like crystal,
flowing clear and unsullied
through my wilderness of life.