King David’s sin is exposed, which leads him to confession, repentance, then joy, because he is assured that God is merciful. He experiences what Jonathan Edwards called “brokenhearted joy” - acknowledging he is sinful, rejoicing that God is a forgiving God.