Psa 7:1a “Shiggaion of David, which he sang unto Jehovah, concerning the words of Cush a Benjamite…”
David was a man of great faith and of great failures. God doesn’t use perfect people, because there are none, but He does use willing hearts. He want’s people after His own heart. Saul was imperfect as well, but he thought knowing God through his relationships with others would suffice. He followed God only partially. In the flesh, he was a “good leader,” but he did not follow the leading of the Spirit. David sought to know God, and God sought him back, through long hours in the wilderness, through trials and triumphs, and through these experiences of doubt, frustration, and anguish.
Remember – the trials are for your good. God wants to know you and for you to know Him. Allow Him to do His work in that.