First, I want to point out an assessment that's made in 1st Kings 15:1-5. It reads as follows:
"In the eighteenth year of the reign of King Jeroboam of Israel, Abijah became king of Judah, and he ruled three years in Jerusalem. His mother was Maacah, the daughter of Absalom. He committed the same sins as his father and was not completely loyal to the Lord his God, as his great-grandfather David had been. But for David's sake the Lord his God gave Abijah a son to rule after him in Jerusalem and to keep Jerusalem secure. The Lord did this because David had done what pleased him and had never disobeyed any of his commands, except in the case of Uriah the Hittite."
-1st Kings 15:1-5
The above portion of scritpure gives us an idea of just how great of an example King David is. First, notice how God chose to make decisions, based on the fact that King David had chosen to follow him. These are generational decisions, that went into effect, long after King David's death. Also, take note of the last sentence.
The last sentence explains just how loyal King David was to God, as he spent his time here, on Earth. Notice that it says he was obedient, except for the terrible sins, that I mentioned before. That's a lot of obedience. Sadly, people, of our time, are quick to dwell on that terrible incident, and ignore how greatly obedient he was, during the majority of his life.
Despite how people tend to want to focus on the few bad things that King David did, we should all take note of what God says in Psalms 89:19-37. I don't think anyone can read this passage, and not realize that King David is an extraordinary example for us to follow. This is because it shows us what God thinks of King David; not the way the world, often, views him.
19 In a vision long ago you said to your faithful servants,
"I have given help to a famous soldier;
I have given the throne to one I chose from the people.
20 I have made my servant David king
by anointing him with holy oil.
21 My strength will always be with him,
my power will make him strong.
22 His enemies will never succeed against him;
the wicked will not defeat him.
23 I will crush his foes
and kill everyone who hates him.
24 I will love him and be loyal to him;
I will make him always victorious.
25 I will extend his kingdom
from the Mediterranean to the Euphrates River.
26 He will say to me,
'You are my father and my God;
you are my protector and savior.'
27 I will make him my first-born son,
the greatest of all kings.
28 I will always keep my promise to him,
and my covenant with him will last forever.
29 His dynasty will be as permanent as the sky;
a descendant of his will always be king.
30 "But if his descendants disobey my law
and do not live according to my commands,
31 if they disregard my instructions
and do not keep my commandments,
32 then I will punish them for their sins;
I will make them suffer for their wrongs.
33 But I will not stop loving David
or fail to keep my promise to him.
34 I will not break my covenant with him
or take back even one promise I made him.
35 "Once and for all I have promised by my holy name:
I will never lie to David.
36 He will always have descendants,
and I will watch over his kingdom as long as the sun shines.
37 It will be as permanent as the moon,
that faithful witness in the sky."
-Psalms 89:19-37