Thank you for asking a question on thisisyourbible.com
Why did David have such trust and confidence in God? Give scripture: How does this revelation affect your faith in God and His Word?
David’s trust and confidence in God came from his study and belief of scripture.
Psalm 18:22 For all His judgments were before me, And I did not put away His statutes from me.
Psalm 19:1 To the Chief Musician. A Psalm of David... 7 The law of the LORD is perfect, converting the soul; The testimony of the LORD is sure, making wise the simple; 8 The statutes of the LORD are right, rejoicing the heart; The commandment of the LORD is pure, enlightening the eyes; 9 The fear of the LORD is clean, enduring forever; The judgments of the LORD are true and righteous altogether. 10 More to be desired are they than gold, Yea, than much fine gold; Sweeter also than honey and the honeycomb. 11 Moreover by them Your servant is warned, And in keeping them there is great reward... 14 Let the words of my mouth and the meditation of my heart Be acceptable in Your sight, O LORD, my strength and my Redeemer.
Psalm 25:8 Good and upright is the LORD; Therefore He teaches sinners in the way. 9 The humble He guides in justice, And the humble He teaches His way. 10 All the paths of the LORD are mercy and truth, To such as keep His covenant and His testimonies.
He understood the necessity of having his sins forgiven and that God would do it.
Psalm 32:1 A Psalm of David. A Contemplation. Blessed is he whose transgression is forgiven, Whose sin is covered. 2 Blessed is the man to whom the LORD does not impute iniquity, And in whose spirit there is no deceit. 3 When I kept silent, my bones grew old Through my groaning all the day long. 4 For day and night Your hand was heavy upon me; My vitality was turned into the drought of summer. Selah 5 I acknowledged my sin to You, And my iniquity I have not hidden. I said, "I will confess my transgressions to the LORD," And You forgave the iniquity of my sin. Selah 6 For this cause everyone who is godly shall pray to You In a time when You may be found;
His trust and confidence came also from recognising God’s hand at work in his life.
1 Samuel 17:37 Moreover David said, "The LORD, who delivered me from the paw of the lion and from the paw of the bear, He will deliver me from the hand of this Philistine."
Psalm 138 shows that he recognised that God knew everything about him and he tried to live accordingly.
Not that he was not assailed by doubt at times in his life.
1 Samuel 27:1 And David said in his heart, "Now I shall perish someday by the hand of Saul. There is nothing better for me than that I should speedily escape to the land of the Philistines;
He is called a man after God’s own heart and promises were made to him concerning his seed. That seed, both son of David and son of God was Jesus Christ who will restore the kingdom of David upon the earth.
Luke 1:32 "He will be great, and will be called the Son of the Highest; and the Lord God will give Him the throne of His father David. 33 "And He will reign over the house of Jacob forever, and of His kingdom there will be no end."
David will be raised from the dead to eternal life in the kingdom as will all those who believe and obey the gospel. By trust and confidence in scripture we share his hope.
I hope this helps.