21 “The Lord dealt with me according to my righteousness;
according to the cleanness of my hands he rewarded me.”
25 “And the Lord has rewarded me according to my righteousness,
according to my cleanness in his sight.” – 2 Samuel 22:21 & 25 (ESV)
Context is important. Referencing God’s strength and might by saying He is our rock and fortress appears frequently in the Psalms of David and others. But this song was written to remember the deliverance God gave him from all his enemies. It could be that David finished this song near the end of his reign. Once they were at war with the Philistines and not ordinary Philistines in this case. David’s army was up against the giants of Gath – the same tribe which Goliath came from. This occasion there were four giants and one in particular is identified in this way; “And there was again war at Gath, where there was a man of great stature, who had six fingers on each hand, and six toes on each foot, twenty-four in number, and he also was descended from the giants.” (2 Samuel 21:20) With God’s might and provision, David’s nephew, Johnathan defeated this monster. David’s army prevailed. David was not claiming to be righteous or sinless in any absolute sense. Rather, David believed God, and was considered righteous by faith. He desired to please the Lord and obey His commands. Thus he was blameless when compared with his enemies.