Note that David's confession does not take the form of some complicated speech to God, nor does it involve deep philosophy. He just repents.
Another depressing episode, appearing toward the end of 2 Samuel, has David ordering a census of his kingdom. The census, itself, was not sinful. Rather, David's haughty attitude in wishing to quantify his power showed a disregard for God's role in the accumulation of that power.
Yet, when David become aware of his sin, he follows the same script as the Bathsheba affair -- his just repents (2 Samuel 24:10, KJV),
David said unto the Lord, I have sinned greatly in that I have done: and now, I beseech thee, O Lord, take away the iniquity of thy servant; for I have done very foolishly.David's life, both the positives and negatives, serves as a prime example of how we should approach God. Let us do likewise.