Using next.jdbc with hikaricp and postgres, what would be the "correct" way to use prepared statements across threads?
In general, don't rely on prepared statements (at least in Postgres) a lot because of two things. 1. In postgres, prepared statements are bound to a certain connection. If you made a prepared statement X in a connection A, you can call X only via A. Calling it from connection B will end up with an error. Since you're working with a connection pool, there is no guarantee you have the same connection all the time. 2. JDBC driver for Postgres caches prepared statements under the hood. Every time you execute something, the prepared connection is cached by the hash from the SQL query. When you execute the same query with different parameters, the driver checks if there is a prepared statement for this hash, and uses it.
Why is the second thing bad? So it doesn't rerun the query?