Now, my son, the Lord be with you, so that you may succeed in building the house of the Lord your God, as he has spoken concerning you. Only, may the Lord grant you discretion and understanding, that when he gives you charge over Israel you may keep the law of the Lord your God.
1 Chronicles 22:11-12
David knew that the secret to his successful long rule in Israel was that God blessed him. The king would never be able to lead without God's wisdom and discretion granting him success. And it is this prayer that David prays that blesses Solomon as David names him as successor and prepares to let the kingdom go over to him.
As I read David's words to Solomon, I can't help but think back to all the ways God has taken care of the shepherd-warrior king. David's reign began with God's gracious choice of him as the least of Jesse's sons, even as king Saul raged against God, eventually trying to kill the young man David before he could ever have the promised throne. But David stayed close to the Lord, and under God's protection, he was spared Saul's rage. And when Saul died in battle against the enemies of Israel, David was ready and able to immediately lead the nation.
David's thoughts on God's grace had to flavor this charge to Solomon. God's grace literally gave David life in the wilderness. It spared him from death by lions, bears, and a Philistine giant while still a boy. It spared him from death when the armies of Saul hunted him like an animal. It spared him from death when his own sins of adultery and murder demanded the death penalty. It spared him disgrace and death when civil war led by his oldest son, Absalom, took the throne from him temporarily. David knew grace his entire lifetime.
And David handed the kingdom to Solomon cognizant of his son's need for God's gracious wisdom to lead. The means for knowing a gracious God in Israel was through the Law of God, so David charges Solomon to keep God's Law close. In that way wisdom, discretion, and understanding could graciously lead him, and the nation.