Like us, the author of Ecclesiastes was discouraged as he saw the injustices in life. He reminds us that even in our attempts to execute righteous judgment, we fail to act righteously (Ecclesiastes 3:16). He grieves that people fail us repeatedly (3:19).
Throughout history powerful people have oppressed the powerless. It can be overwhelming when we continually hear the bad news, and we can easily fall into the depression of Solomon (3:16-4:3).
However, Ecclesiastes was included in the Cannon of Scriptures to demonstrate to us the futility of focusing on this life and not on eternity. To put all our eggs in this basket is to have them broken.
But when we are aware of the unrighteous ways of the world, yet focus on the omnipotent God, we are able to live in peace (John 14:27).