Are you saying that JDBC cannot handle or process \gexec, since it is PG-15 exclusive?
psql is a client application present in all versions of PostgreSQL. It has a bunch of features related to executing SQL queries. The stuff that it is documented to do are only doable by it in many cases, and in all cases are done locally, not by the server. You cannot send those meta-commands to the server, it has no clue what to do with them. And since you are using JDBC you by definition aren’t using psql.
David J.