The title only states that David wrote this Psalm. The last line of this Psalm opens this entire chapter (". . . for I am thy servant."). In this chapter, the Psalmist David comments on how the righteous will gather around him. The righteous in this chapter refers to those who belong to God. David expands upon the thought of who is "righteous" (i.e. in good standing) before God.
He acknowledges he is not a good person because he merely does good deeds, works, actions, etc. Rather his goodness is based upon his perfect standing with God (that is what "righteousness" is) solely because God has completely forgiven him of all his sins. David knows he makes mistakes and he is far from perfect in his life. He is not trusting in his own goodness to approach God, but in the fact that God has perfectly forgiven him of all his sins.
As we bring this truth into our own lives, we understand that God wants for us to live for Him and be pleasing to Him. In order to do this, we like David must ask (". . give ear to my supplications . .") for God's mercy and grace. Mercy because we deserve judgment for our sins; grace because we are an imperfect people who desperately need His love.