Psalm 7:1 & 2
"O Lord my God, I take refuge in you; save and deliver me from all who pursue me, or they will tear me like a lion and rip me to pieces with no one to rescue me." NIV translation
David's reaction to this false accusation was to take it to God in a prayer song. He realized that his only hope was found in God and so it was his first reaction in times of joy as well as in times of sorrow. David was described as a man after God's own heart (see 1 Samuel 13:14) and we see that it is "God's heart" that His people would turn to Him as their first and only option when faced with trials. Just as David knew that God was his refuge, we can know the same in our hearts by the presence of the Holy Spirit.
"O Lord my God, if I have done this and there is guilt on my hands - if I have done evil to him who is at peace with me or without cause have robbed my foe - then let my enemy pursue and overtake me; let him trample my life to the ground and make me sleep in the dust. Selah" NIV translation
We see David declaring his innocence in this passage. He is saying that it would be right if he was being pursued for something that he really did but he is not guilty.
"Arise, O Lord, in your anger; rise up against the rage of my enemies. Awake, my God; decree justice. Let the assembled peoples gather around you. Rule over them from on high; let the Lord judge the peoples." NIV translation
You can almost feel David asking God to call His court into session. He is confident that God is just and so he appeals to Him. We, too, can be confident of the justice of God and it can lift us up in the face of our persecutors.
Psalm 7:8b & 9
"Judge me, O Lord, according to my righteousness, according to my integrity, O Most High. O righteous God, who searches minds and hearts, bring to an end the violence of the wicked and make the righteous secure." NIV translation
David's plea for this court session is that God will search the hearts and minds of everyone and make His judgement. This reminds us that God not only judges actions but also motives (the reason behind the action) and that comes from the heart and the mind.
"My shield is God Most High, who saves the upright in heart." NIV translation
David uses the name El Elyon (God Most High) which speaks of the fact that He created everything and so is in charge of all things. He is supreme and has the final authority over all things. He has the ability to shield His people from the attacks of the enemy. If we are in Christ, then, like David we are His people and this promise is for us as well.
"God is a righteous judge, a God who expresses his wrath every day. If he does not relent, he will sharpen his sword; he will bend and string his bow. He has prepared his deadly weapons; he makes ready his flaming arrows." NIV translation
God makes judgements every day as He is active in the world. He is always ready to judge but He is also patient.
"He who is pregnant with evil and conceives trouble gives birth to disillusionment. He who digs a hole and scoops it out falls into the pit he has made. The trouble he causes recoils on himself; his violence comes down on his own head." NIV translation
David knows that God is just in His judgement and gives to everyone as he deserves. As Paul said, in Galatians 6, "a man reaps what he sows" and that is what David is talking about here. A man can plant the seed with his actions but only God can make it grow.
"I will give thanks to the Lord because of his righteousness and will sing praise to the name of the Lord Most High." NIV translation
David praises God because of who He is and the fact that is decisions are just. That is the same God that we serve today and, so, we can also trust in His righteousness and sing in the face of the enemy and his tactics.