Ecclesiastes 2:1 (CSB) — I said to myself, “Go ahead, I will test you with pleasure; enjoy what is good.” But it turned out to be futile.
Solomon omits any mention of immorality here, as he does elsewhere (Ecc. 7:26) and concerns himself specifically with what may broadly be considered the legitimate joys of pleasure (i.e. Ecc. 7:1–6). The conclusion is that a life spent on personal pleasure ultimately leaves the soul empty and destitute.
Pleasure leads to loneliness because it only lasts as long as its source and its memory quickly fades until it is no longer enough to sustain life with joy. Only when pleasure is the result of something greater than its composite parts does it have any meaning. When pleasure comes from something eternal, then we have something that will last and we know that our heart is in the right place.
Matthew 5:6 (NASB) — Blessed are those who hunger and thirst for righteousness, for they shall be SATISFIED.