David was king over Israel; he sinned against God by committing adultery. When God sent the prophet, Nathan, to show David his sin by telling him a story, David did not recognize the story was concerning him. When Nathan revealed the truth of the story to David, he immediately repented of the sin.
God forgave David, however there were certain changes in the house of David as a result of his sin. David continued as king and walked in obedience to God.
In Acts 13:22 David is said of God to be “a man after mine own heart, which shall fulfill all my will.” David was a man quick to repent of his sin, and obey God’s will; he continued in the path of God, and learned it is best to repent than to hide sin.