David saw God as his deliverer which gave him confidence to act boldly in the face of otherwise overwhelming obstacles.
32 And what more shall I say? For time would fail me to tell of Gideon, Barak, Samson, Jephthah, of David and Samuel and the prophets— 33 who through faith conquered kingdoms, enforced justice, obtained promises, stopped the mouths of lions, 34 quenched the power of fire, escaped the edge of the sword, were made strong out of weakness, became mighty in war, put foreign armies to flight. (ESV)
1 Samuel 17:34-37
34 But David said to Saul, “Your servant used to keep sheep for his father. And when there came a lion, or a bear, and took a lamb from the flock, 35 I went after him and struck him and delivered it out of his mouth. And if he arose against me, I caught him by his beard and struck him and killed him. 36 Your servant has struck down both lions and bears, and this uncircumcised Philistine shall be like one of them, for he has defied the armies of the living God.” 37 And David said, “The Lord who delivered me from the paw of the lion and from the paw of the bear will deliver me from the hand of this Philistine.” And Saul said to David, “Go, and the Lord be with you!” (ESV)
To the choirmaster. A Psalm of David, when Nathan the prophet went to him, after he had gone in to Bathsheba.
51:1 Have mercy on me, O God,
according to your steadfast love;
according to your abundant mercy
blot out my transgressions.
2 Wash me thoroughly from my iniquity,
and cleanse me from my sin!
3 For I know my transgressions,
and my sin is ever before me.
4 Against you, you only, have I sinned
and done what is evil in your sight,
so that you may be justified in your words
and blameless in your judgment.
5 Behold, I was brought forth in iniquity,
and in sin did my mother conceive me.
6 Behold, you delight in truth in the inward being,
and you teach me wisdom in the secret heart.
7 Purge me with hyssop, and I shall be clean;
wash me, and I shall be whiter than snow.
8 Let me hear joy and gladness;
let the bones that you have broken rejoice.
9 Hide your face from my sins,
and blot out all my iniquities. (ESV)