An oft repeated word in Ecclesiastes is translated in the KJV as "vanity":
KJV Ecc 1:2 Vanity of vanities, saith the Preacher, vanity of
vanities; all is vanity.
Brown-Driver-Briggs
I. הֶ֫בֶל73 noun masculine vapour, breath (Late Hebrew id., Syriac id.) figurative vanity (so Late Hebrew, Syriac ) — הָ֑בֶל Ecclesiastes 1:2 +; construct הֲבֵל Ecclesiastes 1:2 (twice in verse); Ecclesiastes 12:8, suffix הֶבְלִי etc. Ecclesiastes 6:12; Ecclesiastes 7:15; Ecclesiastes 9:9 (twice in verse); plural הֲבָלִים Jeremiah 10:8 +; construct הַבְלֵי Jeremiah 8:19 +, suffix הַבְלֵיהֶם Deuteronomy 32:21 +; —
1 literal Isaiah 57:13 all of them (the idols) יִשָּׂארֿוּחַ יִקַּח הָ֑בֶל a breath (ᵑ9 aura) will carry away, Proverbs 21:6 the getting of treasures by a lying tongue is הֶבֶל נִדָּף a vapour driven away. Elsewhere always
2 figurative of what is evanescent, unsubstantial, worthless, vanity, as of idols Jeremiah 10:15 = Jeremiah 51:18; Jeremiah 16:19 הֶבֶל וְאֵין בָּם מוֺעִיל "" (שֶׁקֶרׅ, heathen observances Jeremiah 10:3, and in phrase הָלַךְ אַחֲרֵי הַהֶבֶל Jeremiah 2:5; 2 Kings 17:15; Proverbs 13:11 הוֺן מֵהֶבֶל wealth (gotten) out of vanity, (i.e. not by solid toil, opposed to קֹבֵץ עַל יָד) is minished (but ᵐ5 ᵑ9 Ew מְבֹהָל, see Proverbs 20:21 Qr), Proverbs 31:30 שֶׁקֶר הַחֵן וְהֶבֶל הַיֹּ֑פִי, Lamentations 4:17 אֶל עֶזְרָתֵנוּ הֶבֶל to our vain (Dr§ 193 n.) help; of life Job 7:16 כִּי הֶבֶל יָמָֽי׃, Psalm 78:33 וַיְכַל בַּהֶבֶל יְמֵיהֶם consumed their days as (בְּ I:7 d vanity, man Psalm 39:6; Psalm 39:12; Psalm 62:10 הֶבֶל בְּנֵי אָדָם ֗֗֗ הֵמָּה מֵהֶבֶל יָחַד׃ they are altogether (made) of vanity, Psalm 94:11; Psalm 144:4, especially in Ecclesiastes (31 t. + הֲבֵל הֲבָלִים Ecclesiastes 1:2 (twice in verse); Ecclesiastes 12:8) of the fruitlessness of all human enterprise and endeavour, Ecclesiastes 1:2 הַכֹּל הֶבֶל, Ecclesiastes 1:14 הַכֹּל הֶבֶל וּרְעוּת רוּחַ all was vanity and the pursuit of wind, Ecclesiastes 2:1,14,15 etc., Ecclesiastes 6:4 (of an abortion) בַּהֶבֶל בָּא i.e. into a lifeless existence, Ecclesiastes 6:11 יֵשׁ דְּבָרִים הַרְבֵּה מַרְבִּים הָ֑בֶל (of discussions leading to no result), note also the phrases יְמֵי (הֶבְלוֺ, הֶבְלְךָ) הֶבְלִי Ecclesiastes 7:15; Ecclesiastes 9:9, ׳יְמֵי חַיֵּי ה Ecclesiastes 6:12; Ecclesiastes 9:9; Job 27:12 (see הָבַל), Isaiah 49:4 לְתֹהוּ וָהֶבֶל for nought and vanity have I spent my strength; as adverb accusative vainly, to no purpose Isaiah 30:7 הֶבֶל וָרִיק יַעֲזֹ֑רוּ, Psalm 39:7 אַךְ הֶבֶל יֶהֱמָיוּן they disquiet themselves to no purpose, Job 9:29: הֶבֶל אִיגָָֽע Job 35:16, with נִחַם to comfort Job 21:34; Zechariah 10:2. Plural הֲבָלִים of false gods, Deuteronomy 32:21 ) כִּעֲסוּנִי בְהַבְלֵיהֶם "" בְּלֹאאֵֿל) 1 Kings 16:13,26; Jeremiah 8:19 הַבְלֵי נֵכָר "" (בִּפְסִילֵיהֶםׅ, Jeremiah 10:8; Jeremiah 14:22 הַבְלֵי הַגּוֺיִם, Psalm 31:7 הַשֹּׁמְרִים הַבְלֵישָֿׁוְא empty vanities Jonah 2:9; in more General sense Ecclesiastes 1:2 (twice in verse); Ecclesiastes 12:8 הֲבֵל הֲבָלִים, Ecclesiastes 5:6.
https://biblehub.com/hebrew/1892.htm
In the text the author complains endlessly about what a "scam" everything in this world is. Everything in this life disappoints. The protagonist, Solomon is a rich king so he has the rare opportunity to basically do whatever he wants. And he does. He "has it all". He is "living the dream". But the promise that he can buy or achieve happiness from the things of this world is an empty one and though he goes from one pursuit to another he never finds anything to "fill the void" and satisfy his empty soul. He concludes that the one thing that is worth anything is to "fear God and keep his commandments":
ESV Eccl 12: 12My son, beware of anything beyond these. Of making many
books there is no end, and much study is a weariness of the flesh.
13The end of the matter; all has been heard. Fear God and keep his
commandments, for this is the whole duty of man.c 14For God will bring
every deed into judgment, withd every secret thing, whether good or
evil.
So it is not surprising that Solomon, despite his many wives finds "love" to be "a scam". This viewpoint, intentionally bleak as is the whole book is part of his overall message that there is nothing in this world that satisfies except the divine instruction/commands.
As to why there is a man who is righteous when women are all disappointing, perhaps the single righteous man is intended to be an allusion to the messiah:
ESV Acts 3:14 But you denied the Holy and Righteous One, and asked
for a murderer to be granted to you,