Romans 4:2-3 If his good deeds had made him acceptable to God, he would have had something to boast about. But that was not God's way. For the Scriptures tell us, "Abraham believed God, and God counted him as righteous because of his faith."
You see this in David too... David did wrong... David questioned when God was going to do what He said...but David always had faith that God was going to do what God said He would do. David was counted righteous by his faith too.
To have this kind of faith we need to know what God's word says. When we know what God's promises are we can see them being answered all around us. Witnessing God's promises being fulfilled grows our faith. So often we are witness to God's promises being fulfilled and we don't know it...because we have failed to educate ourselves on the promises of God.
Years ago I asked Jesus into my heart. I tried to be good and do good... I was trying to get to heaven on my good works. I would always wonder if I was good enough...would God want me in heaven? If I had know I was dieing I would have been terrified. Oh I would go to church (on and off) and try to learn and understand...but I always felt empty somehow...not good enough to get into heaven. Then I would fail miserably...because I just couldn't keep up with being so good!! I would stop trying! It was a never ending cycle.
Then I started reading my Bible every day...and slowly but surly understanding it... wanting more all the time to understand it!! I begin to understand that God loves me no matter what!! I begin to read about the promises of God...and see them played out in people's lives....and I started to become aware when those promises were played out in my life. I could be aware of then because I finally knew what they were. The more I saw God answering people's prayers...the more my faith grew. The more my faith grew the more I knew that God loves me, no matter! God loves me even when I mess up! The more I understood just how much God loves me...the better I got at being good...not because being good would get me into heaven...but because being good would please my God that loves me so much!! The more I understand God and just how much He loves me...the more I call on Him to help me be good, to help me make the right decisions...the more I put my faith in Him to make me a better person.
Before I was trying to be right by what I did... now I am right because I am a child of the Most High God who makes me right because I love Him, because I have faith that He loves me. I don't give up when I mess up anymore...because I know that what it do is not what makes God love me.... God just loves me... I know that I don't have to be afraid to go to God and say "I did this _____." God already knows what I did and He loves me anyway...so much that Jesus died already for what I did wrong. I don't have to pick myself up, God pick me up and puts me right back on solid ground..and I get to start moving forward in His love again. God doesn't condemn me...He picks me up and loves me... it is like he hugs me tight and says "I love you so much!" Then He takes my face in His hands and says "Let me help you, did you learn something? Good!! Now here is how to do it better next time...don't forget to take my hand when you get there and I will help you do better...I am always here for you... I love you!! Everything is all right." I know these things because I know God's word now.
If you don't feel these things..it is not because they are not there for you...they are... God loves you so much! You just have to learn what is there for you... you just have to read God word over and over and over so you can recognize when those promises are being fulfilled around you, for you... that will grow your faith...and faith is what makes us right with God.