Faithfulness, patience, courage, generosity, commitment, honesty--these are just a few characteristics that describe King David. Second Samuel is full of these and more as they follow David's God honoring life.
It seems David stands out most in the Bible second to Jesus himself. He was born halfway between Abraham and the Jesus and became a legendary leader of Israel and an ancestor to the Messiah.
David is who God chose:
"The Lord has sought out a man after his own heart. The Lord has already appointed him to be the leader of his people." 1 Samuel 13:14
King David does many righteous things after he is crowned king of Israel (5:1-5). He bring the Ark of the Covenant back to the Tabernacle (6:1-23) and he leads military victories completing the conquest of the Promised Land which Joshua began many years before (8-10).
However, even King David was subject to temptation and sin. His eyes filled with lust when he saw Bathsheba and slept with her even though he knew she was married. And then, he put her husband on the front lines to die in order to keep her (11:1-27). The Lord was not pleased with David. But David repents and God forgives him. Even though he loses one son, Bathsheba gave birth to Solomon, a great successor to King David.
The point is not that David sinned. As great a person he was, he was not perfect. We all sin. We are all human and fall short of the glory of God. The point is, David repented. This story has a happy ending. God loved David so much, he protected Israel for all time. The point of the story is: you can learn valuable lessons from your sins and allowing God to lead you back to a close relationship with Him. There can be greatness out of sin if we righten our hearts with God. We should always strive to be a person after God's own heart, just like David was.