When God gave Israel a king, he first chose Saul. But Saul became proud and overstepped his position and God was displeased with him. So God chose himself a new king, and he sent Samuel to anoint him. It would take years before David would actually become the king of Israel. He would have to wait for Saul to die, and Saul would make his life miserable for a long time before then.
1 Now the LORD said to Samuel, "How long will you grieve over Saul, since I have rejected him from being king over Israel ? Fill your horn with oil and go ; I will send you to Jesse the Bethlehemite, for I have selected a king for Myself among his sons." 2 But Samuel said, "How can I go ? When Saul hears of it, he will kill me." And the LORD said, "Take a heifer with you and say, 'I have come to sacrifice to the LORD.' 3 "You shall invite Jesse to the sacrifice, and I will show you what you shall do ; and you shall anoint for Me the one whom I designate to you." 4 So Samuel did what the LORD said, and came to Bethlehem. And the elders of the city came trembling to meet him and said, "Do you come in peace ?" 5 He said, "In peace ; I have come to sacrifice to the LORD. Consecrate yourselves and come with me to the sacrifice." He also consecrated Jesse and his sons and invited them to the sacrifice. 6 When they entered, he looked at Eliab and thought, "Surely the LORD'S anointed is before Him." 7 But the LORD said to Samuel, "Do not look at his appearance or at the height of his stature, because I have rejected him; for God sees not as man sees, for man looks at the outward appearance, but the LORD looks at the heart." 8 Then Jesse called Abinadab and made him pass before Samuel. And he said, "The LORD has not chosen this one either." 9 Next Jesse made Shammah pass by. And he said, "The LORD has not chosen this one either." 10 Thus Jesse made seven of his sons pass before Samuel. But Samuel said to Jesse, "The LORD has not chosen these." 11 And Samuel said to Jesse, "Are these all the children ?" And he said, "There remains yet the youngest, and behold, he is tending the sheep." Then Samuel said to Jesse, "Send and bring him; for we will not sit down until he comes here." David Anointed 12 So he sent and brought him in. Now he was ruddy, with beautiful eyes and a handsome appearance. And the LORD said, "Arise, anoint him; for this is he." 13 Then Samuel took the horn of oil and anointed him in the midst of his brothers ; and the Spirit of the LORD came mightily upon David from that day forward. And Samuel arose and went to Ramah. (1 Samuel 16:1-13 NASB)
But God chose David, and God's spirit was very strong with him, and David was a mostly good man. He acted as God would want him to act.
There was this one time, he did something very wrong, and he and all the people suffered as a result. But even then, he turned to God, and God forgave him.
David was, in a lot of ways, the kind of king God wanted for Israel to have, even though he was human, and still made mistakes. His heart was the kind of heart God looks for.
It is the descendants of David that God establishes on the throne of of Israel. It is descendants of David who are considered by Israel to be the true kings. It will be a descendant of David who will bring deliverance.
1 Then a shoot will spring from the stem of Jesse, And a branch from his roots will bear fruit. 2 The Spirit of the LORD will rest on Him, The spirit of wisdom and understanding, The spirit of counsel and strength, The spirit of knowledge and the fear of the LORD. 3 And He will delight in the fear of the LORD, And He will not judge by what His eyes see, Nor make a decision by what His ears hear ; 4 But with righteousness He will judge the poor, And decide with fairness for the afflicted of the earth ... 9 They will not hurt or destroy in all My holy mountain, For the earth will be full of the knowledge of the LORD As the waters cover the sea. (Isaiah 11:1-4, 9 NASB)Who was Jesse again? That's right, David's father.
In a dark, dark time, when all in Israel think hope is lost, God sends this promise, that there will be a king again, a righteous king with God's spirit in him. This is the hope they cling to when it seems all is lost. This is the hope we all cling to when it seems all is lost, that God will still keep his promise that he made, so long ago.