Summary: Looking at David’s example - his confidence in the midst of hardship is not the result of the absence of trouble, but the presence of God.
David was able to say "I will be confident" (v.3) even in the midst of hardship and trouble. We can make 3 observations form these 3 verses:
(1)His confidence is not the result of the ABSENCE of problems.
It is very clear that David encountered many problems and difficulties. He mentioned evil men attacking him, he said they were his enemies, an army besiege him and war break out against him. He was surrounded by problems and hardships.
In fact, we read of many godly servants of God in the Scriptures who had to overcome hardships. In the OT, we read of Joseph being betrayed by their brothers, sold as slave to Egypt, wrongly accused and was imprisoned for several years. Yet throughout this whole period of time Joseph did not complain against God. Eventually his whole family came to Egypt to seek help because of a famine in their homeland. And this was what Joseph said, "You intended to harm me, but God intended it for good to accomplish what is now being done, the saving of many lives." (Gen 50:20).
We read of others, like Daniel, Nehemiah, Esther, prophets Jeremiah, Hosea... they went through various hardships. Yet they stood firm, trusted God and eventually overcame the difficulties they faced. Jesus told his disciples very clearly - John 16:33 (quickview)  "...In this world you will have trouble. But take heart! I have overcome the world."
Last week, we heard the testimony of Sis Sun Qin - they’ve had a rough journey, yet through it all God has drawn them to Himself. Knowing Jesus, and being saved, is all that really matters. As Paul said, "I consider that our present sufferings are not worth comparing with the glory that will be revealed in us." (Rom 8:18). The glorious inheritance, eternal life with Him, is what God longs to give to each of us.
Some of us may be facing some tough times - medical problems, difficult family situation, financial needs, your future is uncertain - when these things happen it is very easy for us to worry and be afraid. God does not want that to happen - if we are a believer in Jesus, we should not be afraid of what the future holds - because it is our heavenly Father who holds that future in His hands. He knows what you need, and it is already in His hands.
And that’s what David showed us in this psalm...
(2)His confidence is a result of the PRESENCE of God IN our problems.
In the midst of his difficulties, David kept focusing on God and not on his difficult situation. He says, the Lord is my light, the Lord is my salvation, the Lord is the stronghold of my life. It was because his eyes were on God that he was able to say, "Of whom shall I be afraid?"
Rom 8:31-32 31What, then, shall we say in response to this? If God is for us, who can be against us? 32He who did not spare his own Son, but gave him up for us all - how will he not also, along with him, graciously give us all things?
He is my light... in the midst of darkness, when I can’t see the road. Psalm 23:4 (quickview)  "Even though I walk through the valley of the shadow of death..." Why the psalmist use the word "shadow" - because the road was dark. Only in the night will we see shadows. He was going through dark moments in his life. It was night, not day. Yet it was just a shadow - in other words, there was a light present with him... if there was no light, there would not be any shadow. Where does this light comes from? The psalmist goes on, "I will fear no evil, for You are with me; Your rod and Your staff, they comfort me." GOD IS WITH HIM.