Here is a helpful answer to that question from Tremper Longman’s essay, “Why Do Bad Things Happen to Good People? A Biblical-Theological Approach,” in the new book, Eyes to See and Ears to Hear: Essays in Memory of J. Alan Groves, ed. Peter Enns, Douglas J. Green, and Michael B. Kelly (Phillipsburg, NJ: P&R, 2010), pp. 13-14:

Our presentation of the material above may lead to a misconception if not read carefully. Proverbs emphasizes the rewards that come to those who follow the way of wisdom, while Job and Ecclesiastes question the connection between behavior and consequences. Does that mean that Job and Ecclesiastes contradict Proverbs, not to speak of the other strands of the OT that imply that good things happen to good people and bad things happen to bad people?

Close study of these books suggests a negative answer. In the first place, Proverbs does not guarantee reward to the righteous or punishment for the wicked. A proverb is simply not in the business of issuing promises or guarantees. Rather, a proverb states the best route to a desired end, all other things being equal. Most of the time it is true that lazy behavior will lead to poverty and hard work will result in a better living standard, but not always. An indolent person could inherit a fortune, or a hard worker might be wiped out by a natural calamity or a crooked administrator. Proverbs 13:23 acknowledges the latter when it says:

A poor person’s farm may produce much food,
but injustice sweeps it all away.

Another indication that Proverbs itself does not believe there is a mechanical and absolutely guaranteed connection between wise behavior and good benefits is in its acknowledgment that the fool can have wealth—even if only temporarily:

Wealth from get-rich-schemes quickly disappears;
wealth from hard work grows over time. (13:11)

But even when the wealth of fools might last, it does not really help the person:

Riches won’t help on the day of judgment. (11:4a)

Thus, a number of better-than proverbs imply that a person may have to decide between wisdom and success in life:

Better to be poor and godly
than rich and dishonest. (16:8; see also 15:17; 16:16; 17:1; 22:1; 28:6)

In conclusion, Ecclesiastes and Job do not correct Proverbs, but rather they correct an overreading of Proverbs.