I was also upright - The times in which David was most afflicted were the times of his greatest uprightness. Adversity was always to him a time of spiritual prosperity.
Mine iniquity - Probably meaning what is generally termed the easily-besetting sin; the sin of his constitution, or that to which the temperament of his body most powerfully disposed him. What this was, is a subject of useless conjecture.
I was also upright before him - Margin, with. The meaning is that he was upright in his sight. The word rendered upright is the same which in Job 1:1 is rendered perfect. See the note at that passage.
And I kept myself from mine iniquity - From the iniquity to which I was prone or inclined. This is an acknowledgment that he was prone to sin, or that if he had acted out his natural character he would have indulged in sin - perhaps such sins as had been charged upon him. But he here says that, with this natural proneness to sin, he had restrained himself, and had not been deserving of the treatment which he had received. This is one of those incidental remarks which often occur in the Scriptures which recognize the doctrine of depravity, or the fact that the heart, even when most restrained, is by nature inclined to sin. If this psalm was composed in the latter part of the life of David (see the introduction), then this must mean either
(a) that in the review of his life he felt it had been his general and habitual aim to check his natural inclination to sin; or
(b) that at the particular periods referred to in the psalm, when God had so wonderfully interposed in his behalf, he felt that this had been his aim, and that he might now regard that as a reason why God had interposed in his behalf.
It is, however, painfully certain that at some periods of his life - as in the matter of Uriah - he did give indulgence to some of the most corrupt inclinations of the human heart, and that, in acting out these corrupt propensities, he was guilty of crimes which have forever dimmed the luster of his name and stained his memory. These painful facts, however, are not inconsistent with the statement that in his general character he did restrain these corrupt propensities, and did “keep himself from his iniquity” So, in the review of our own lives, if we are truly the friends of God, while we may be painfully conscious that we have often given indulgence to the corrupt propensities of our natures - over which, if we are truly the children of God, we shall have repented - we may still find evidence that, as the great and habitual rule of life, we have restrained those passions, and have “kept ourselves” from the particular forms of sin to which our hearts were prone.