"The Lord has rewarded me according to my righteousness; According to the cleanness of my hands He has recompensed me. "For I have kept the ways of the Lord, And have not acted wickedly against my God. "For all His ordinances [were] before me; And [as for] His statutes, I did not depart from them. "I was also blameless toward Him, And I kept myself from my iniquity. "Therefore the Lord has recompensed me according to my righteousness , According to my cleanness before His eyes. "With the kind Thou dost show Thyself kind, With the blameless Thou dost show Thyself blameless; with the pure Thou dost show Thyself pure, and with the perverted Thou dost show Thyself astute. (22:21-27)
Now, I don't know about you, but this doesn't sound very "grace-through-faithish." It sounds as though this person is claiming that his righteousness has come from a sinless life. Of course, the problem with that is that the person saying this is David.
Now, of course, one might argue that this is David's faulty theology that is later corrected after his many sins (the most well known being that of his adulterous affair and plot to have the husband of the woman with whom he committed adultery killed in battle--think of how wicked this same action is portrayed in the movie, "The Man in the Iron Mask," where the king does the same to a poor peasant in order to take his fiancé for himself); but I don't think this is said because David doesn't get it yet.
One could also say that the salvation here is a lesser physical salvation and not spiritual, but David is claiming to be given this physical deliverance (which often represents spiritual salvation in the OT) because he is righteous and did not depart from the statutes of the Lord.
I think the problem is the concept we have of righteousness and how it is acquired throughout the Bible. We think that not departing from God's statutes means that we never sin, but that is not the way the OT presents it. Notice Psalm 32 that bridges the gap for us between our thinking and biblical thinking:
([A Psalm] of David. A Maskil.) How blessed is he whose transgression is forgiven, Whose sin is covered!
How blessed is the man to whom the Lord does not impute iniquity, And in whose spirit there is no deceit!
When I kept silent [about my sin], my body wasted away Through my groaning all day long.
For day and night Thy hand was heavy upon me; My vitality was drained away [as] with the fever heat of summer. Selah.
I acknowledged my sin to Thee, And my iniquity I did not hide; I said, "I will confess my transgressions to the Lord"; And Thou didst forgive the guilt of my sin. Selah.
Therefore, let everyone who is godly pray to Thee in a time when Thou mayest be found; Surely in a flood of great waters they shall not reach him.
Thou art my hiding place; Thou dost preserve me from trouble; Thou dost surround me with songs of deliverance. Selah.
I will instruct you and teach you in the way which you should go; I will counsel you with My eye upon you.
Do not be as the horse or as the mule which have no understanding, Whose trappings include bit and bridle to hold them in check, [Otherwise] they will not come near to you.
Many are the sorrows of the wicked; But he who trusts in the Lord, lovingkindness shall surround him. Be glad in the Lord and rejoice, you righteous ones, And shout for joy, all you who are upright in heart.
Notice that David's understanding of righteousness is a life lived in seeking to do what is right, but this includes seeking to ask for forgiveness when we sin. It includes acknowledging our sin before God and to ourselves. A righteous life is one that is lived in repentance. Righteousness, therefore, is not the attribute of a sinless life because we have not sinned, but because our sin has not been attributed to us. God has not taken it into account, but has attributed godliness to the individual instead. So righteousness is given, not earned, through the act of asking for it and trusting in God for it (notice, he who trusts in the Lord will have His unfailing love surround him).
But does this mean that one can just go on sinning and ask for forgiveness and be righteous? No. Both this Psalm and the one we saw earlier tell us that the righteous seek God when He can be found (i.e., when we are attempting to give our lives over to Him to do His will). The Psalm above says that in a flood of great waters God will not be found. In other words, if your life is one that is simply accumulating unrepentant sin upon unrepentant sin, God will not hear your prayers. Your life simply evidences no desire to live in God's will. The righteous person is a person who wants righteousness. He just doesn't have it unless God gives it to him. When God does set him upright, he wants to live there in loving relationship with God. If he falls down, he wants God to pick him back up in order that he might continue to live out the will of God.
What this means to me is that the modern inclination toward both seeing righteousness in licentious terms (where righteousness is just given to me through grace, but not a grace through faith, regardless of my chosen lifestyle) and as something that comes through our works is wrong. Grace is given, not only to those who seek God's forgiveness, but do so within a relationship with Him that is characterized by the disposition and desire toward the doing of good and the refraining from evil. In other words, our trusting in the Lord refers to a particular type of relationship we are to have with God, where He is our Lord, Master, Father, Shepherd, Teacher, Friend. We cannot maintain, or even enter, such a relationship without God's forgiving grace, as we will sin, and sin horribly, in life. Righteousness, then, comes to the one who seeks it through repentance. Godliness is not found in perfection, but in the desire to be pleasing to God even when we are not.
Of course, what David only had shadows of, we have a greater revelation to know just how God can be just and the justifier of sinners. God cannot merely wave His hand and let our evil go, but He seeks to justify us and satisfy justice according to the wrong committed. Hence, without Christ, the Old Testament has no foundation for understanding God as both just and the justifier of those who sin. The law itself only allows for animals to propitiate/expiate ritual impurities and clueless transgressions (i.e., those cases where sins are inadvertently committed). Willful sins are to be taken out upon the perpetrator. There is no sacrifice for them. At least this is the case in the law, sacrifices do begin to be seen as propitiatory toward sin as the Old Testament approaches the New (e.g., Job sacrificing for his children in case they have cursed God in their hearts--but this is for internal sins not discussed in the law, not explicit acts, as in David's case). Hence, unless God, who is not bound by our chronology, could see David's sin upon His crucified Son, there would be no forgiveness of David's iniquities. There would be no righteousness given. There would be no godly people. Hence, Paul preached only Christ and Him crucified as his central message concerning righteousness because without it, righteousness cannot be acquired.
Indeed, how blessed is the man whose sins God does not take into account. He is a righteous man, a godly man, who will be rewarded for his righteous life that sought God out for forgiveness and grace; but this very righteousness for which he is being rewarded was given to him in the first place. Hence, many are the sorrows of the wicked because they are not honest to themselves and before God about their sin, but the righteous who trust in the Lord are righteous because they trust in the Lord. It is they who shout for joy in their upright hearts/minds, not because they are perfect people, but because they seek out the Lord for love, mercy, and forgiveness when He can be found. It is through a life that seeks to live in the Lord, a life that seeks forgiveness in repentance and faith, that is the one that has "kept the ways of the Lord" (2 Sam 22:22). There is no perfectly lived life, only imperfect lives that are given perfection in Him. So blessed is David who was forgiven, not because he was as pure as Christ, but because he was made a godly, upright, and righteous man by Him.