While David sinned to serve his own sinful purposes, God worked the sin out for good, the ultimate good, according to His purpose!
David
Hymn of the Day: Psalm 51 (Wisdom in the Secret Heart)
Create in me a clean heart, O God, and renew a right spirit within me.
The Lord Will Perfect that which Concerneth Me
If we indulge in any confidence which is not grounded on the Rock of ages, our confidence is worse than a dream, it will fall upon us, and cover us with its ruins, to our sorrow and confusion.