Historical commentary by Matthew Henry. The wording and interpretations below belong to the original source.
This is a reason why David reckoned that when by his afflictions he learned God's statutes, and the profit did so much counterbalance the loss, he was really a gainer by them; for God's law, which he got acquaintance with by his affliction, was better to him than all the gold and silver which he lost by his affliction. 1. David had but a little of the word of God in comparison with what we have, yet see how highly he valued it; how inexcusable then are we, who have both the Old and New Testament complete, and yet account them as a strange thing! Observe, Therefore he valued the law, because it is the law of God's mouth, the revelation of his will, and ratified by his authority. 2. He had a great deal of gold and silver in comparison with what we have, yet see how little he valued it. His riches increased, and yet he did not set his heart upon them, but upon the word of God. That was better to him, yielded him better pleasures, and better maintenance, and a better inheritance, than all the treasures he was master of. Those that have read, and believe, David's Psalms and Solomon's Ecclesiastes, cannot but prefer the word of God far before the wealth of this world.
Source details
Source introductions and embedded Scripture quotations are preserved here as part of the historical edition.
Source Scripture quotation
72 The law of thy mouth is better unto me than thousands of gold and silver.