Summary: Everybody messes up now and again. How you feel about it and what you do about it makes a huge difference. Find out how David handled sin in a wonderful way we can learn from.
It seems like in Psalm 31 (quickview)  David is receiving the consequences of a sin unknown to us. It has caused others around him to shun him and talk maliciously about him. In the psalm, though, David recommits his life to Yahweh and seeks God’s forgiveness and God’s answers to his plight. It’s a great lesson for us as well when we suffer for what we have done.
1 – 5
David’s plea should be familiar to us by now—seeking refuge in God and asking for His salvation, leading, guidance, and redemption. He knows he has blown it and asks for God’s rescue, not so he can go out and sin again but so that God will be glorified. “Save me by Your righteousness” he says in verse 1, “You lead and guide me because of Your name” in verse 3.
Two things to note in verse 5. The beginning of the verse makes up Jesus’ final words on the cross. Jesus Himself had not sinned but was being judged for all of our sin. After He had paid the price He then committed Himself into God’s hands, and died. Secondly, notice David is asking for God to redeem him and calls the Lord “God of truth.” I like that. We don’t ask God to look the other way or violate His character when He saves us. We truthfully face what we have done and then see those things put upon the shoulders of Jesus Christ which means they are lifted off of our shoulders!
6 – 8
David reiterates that he has a relationship with God and has severed his relationship with any other thing that stands before God being first in his life. And he recognizes that it is God’s covenant (“Faithful”) love that allows David to rejoice even in suffering for his sins. We don’t rejoice in the sin but rejoice that God can forgive and wipe away the sin.
I also want to point out that when we mess up God doesn’t sit up on heaven and smirk saying “now they’re going to pay!” God feels the consequences of our mistakes more than we do and desires that we not fall prey to the enemy but are redeemed, forgiven, and set back in a right place.
9 – 13
Here is where David admits that it is his own actions that have led him here. Notice he says “angry sorrow” in verse 9. I like that. We ought to have an angry sorrow against sin in our life.
Godly grief says “Lord I’ve blown it, forgive, cleanse, and teach me Your character.” Worldly grief is just sorry to have gotten caught.
David is feeling the consequences of his actions. People are actually running from him and talking about him.
Galatians 6:7-9 (quickview)  “Do not be deceived, God is not mocked; for whatever a man sows, that he will also reap. 8 For he who sows to his flesh will of the flesh reap corruption, but he who sows to the Spirit will of the Spirit reap everlasting life.” NKJV
14 – 18