AS I WAS STUDYING A PART OF A BOOK I HAVE ON DIFFICULTIES IN THE BIBLE, I CAME ACROSS THIS QUESTION AND ANSWER——
In the light of his dealings with Bathsheba and her husband, Uriah, how could David be regarded by the Lord as a servant whose heart was "perfect" before Him (cf. 1 Kings 11:4; 15:3; Acts 13:22)?
Even before David became king of Israel, he had committed several sins and offenses to his discredit. His deception of the high priest Ahimelech resulted in the massacre of nearly every priest in the city of Nob by the agents of King Saul, even though they were completely unaware of David's status as a wanted fugitive (1 Sam. 21-22). Later on, as a vassal of King Achish of Gath, David systematically deceived him as to the various tribes and communities his warriors had raided in their forays from Ziklag; and he was willing to put every one of his victims to death in order to keep the truth about his activities from getting back to Achish (1 Sam. 27:8-12). His affair with Uriah's wife, Bathsheba, and the subsequent cover-up that he engineered by having Uriah killed in battle before the walls of Rabbath Amrnon (2 Sam. 11) were by no means the only shameful blots on his record, even though they are doubtless the best known.
From these considerations it is quite apparent that David did not gain God's favor or approval because of a sinless life. Although his conduct was for the most part exemplary and his courage and ability as a leader beyond comparison, it was not because of these things that he especially pleased God. It was rather because of his tremendous faith in the power and grace of God that his heart was adjudged to be salem (KJV, "perfect"; NASB, "wholly devoted"; NIV, "fully devoted") with Yahweh his God (1 Kings 11:4; 15:3). The adjective salem basically means "complete, whole, sound, finished" or even "at peace with ['im] someone." (The word is cognate with solom, "peace, welfare.") That is, David's heart was all there for God, and God was his very reason for living. Many of his psalms eloquently express his deep attachment to the Lord, his joy in fellowship with God, and his complete trust in His redeeming power.
Furthermore, David could never remain out of fellowship with God for very long. Psalm 32 reveals what unbearable agony he went through after the affair with Bathsheba, until finally the prophet Nathan came to him and condemned his crimes in the name of Yahweh (2 Sam. 12:7-10). A lesser man would have flared up against this daring prophet and had him put to death. But one of the greatest assets in David's character was his ability to receive rebuke, to acknowledge his utter sinfulness (cf. Ps. 51:3-5), and to cast himself on the mercy of God to forgive him, cleanse him, and restore him to holy fellowship once more.
The believer who can face guilt and failure in the way David did is in a profound sense a man after God's own heart—the kind that God told Samuel He was going to look for after Saul had forfeited favor by his disobedience (1 Sam. 13:14). David was that kind of a son and servant to the Lord; he was an 'is kilebabo ("a man according to His heart"). As such he became a model for all believers to follow, in regard to wholehearted commitment to pleasing the Lord, obeying His word, and furthering the cause of His kingdom on earth. God could trust him with great responsibility and consistent victory on the battlefield because David's central purpose was to glorify God, not to glorify or please himself.
Recalling these dominant traits in David's life, the apostle Paul commended him to the congregation in Antioch Pisidiae, saying: "And after He had removed him [Saul], He raised up David to be their king, concerning whom He also testified and said, 'I have found David the son of Jesse, a man after My heart [kata ten kardian mou], who will do all My will" (Acts 13:22, NASB).
The glory of God, the will of God, and the loving fellowship of God were what mattered most to King David, even though there were temporary lapses in that relationship. But even after he had fallen into sin and failure, David knew how to trust God's grace and forgiving love enough to confess and forsake his iniquity in an attitude of true repentance so as to get back in step with the Lord on the highway of holiness. Such a believer is certain to be a man or woman after God's own heart!...END QUOTE
IT IS THE TRUTH OF THE MAN AND KING OF ISRAEL— DAVID.
IT SHOULD GIVE US ALL INSPIRATION FOR THE CHRISTIAN WAY OF LIFE. IN DAVID’S SITUATION BECAUSE HE WAS KING OF ISRAEL, HIS SINS WOULD HAVE OR COULD HAVE A MORE SERIOUS CONSEQUENCE, THAN THE SINS OF THE AVERAGE MAN ON THE STREET SHALL WE SAY. HENCE HIS PENALTY FOR THOSE SINS HAD A BROADER PATH.
WE SEE THAT GOD IS NO RESPECTER OF PERSONS; HE JUDGES RIGHTEOUSLY. IT MATTERS NOT THAT YOU ARE “A NOBODY” OR A “SOMEBODY”—— GOD JUDGES RIGHTLY AND FAIRLY WITH EVERYONE.
WHAT IS INSPIRING TO SEE IS THAT NO MATTER WHAT YOUR SINS, UPON TRUE DEEP REPENTANCE, YOU CAN BE FORGIVEN. THERE IS NO SIN THAT GOD CANNOT WASH AWAY IN THE BLOOD OF OUR SAVIOR JESUS THE CHRIST, UPON OUR ADMITTANCE TO THE SIN, AND OUR WHOLEHEARTED REPENTANCE.
WITH THAT REPENTANCE COMES OUR MIND-SET OF WANTING TO KNOW GOD’S WAYS, HIS RIGHTEOUSNESS—— WANTING TO LOVE THE WAY OF GOD AND TO DO THE WAY OF GOD.
THIS WAS THE MIND-SET OF DAVID—— WE SEE HIS MIND-SET IN PSALM 51 AND PSALM 1, AS WELL AS PSLAM 23.
THIS IS TO BE OUR MIND-SET.
SO HAVING, GOD WILL ALSO SAY TO US, YOU ARE A PERSON AFTER MY OWN HEART.