1 Kings - Chapter 15
"Abijam began to rule over Judah in the eighteenth year of Jeroboam’s reign in Israel. ... He committed the same sins as his father before him, and he was not faithful to the Lord his God, as his ancestor David had been. But for David’s sake, the Lord his God allowed his descendants to continue ruling, shining like a lamp, and he gave Abijam a son to rule after him in Jerusalem. For David had done what was pleasing in the Lord’s sight and had obeyed the Lord’s commands throughout his life, except in the affair concerning Uriah the Hittite."
Abijam committed sins and was not faithful to God - but he was blessed because of the faithfulness of David. This is a picture of the world. Even though all fall short, God's blessings is possible because Jesus obeyed the Lord and did what was pleasing in His sight.