I think these are the words of a fallen preacher who is regurgitating all of his errors in life. The entire book is tongue in cheek and is not what we should believe, rather a reciting of his mistakes and what we should not believe... like the verses that follow your quote.
Do not be excessively righteous, and do not be overly wise. Why should you ruin yourself?
Ecclesiastes 7:16
At some point in his life he held these things to be true.
Most are obviously wrong headed.
I am always surprized when people quote Eccl as what we should believe.
They need to study the entire book and find out what it is all about.
History bears witness, is this true? So we see that inspiration comes from many vantage points.
3:3 For everything there is a season, and a time for every matter under heaven:
2 a time to be born, and a time to die;
a time to plant, and a time to pluck up what is planted;
3 a time to kill, and a time to heal;
a time to break down, and a time to build up;
4 a time to weep, and a time to laugh;
a time to mourn, and a time to dance;
5 a time to cast away stones, and a time to gather stones together;
a time to embrace, and a time to refrain from embracing;
6 a time to seek, and a time to lose;
a time to keep, and a time to cast away;
7 a time to tear, and a time to sew;
a time to keep silence, and a time to speak;
8 a time to love, and a time to hate;
a time for war, and a time for peace.