According to the PostgreSQL documentation, a prepared statement is bound to a database session/connection:
PREPARE creates a prepared statement. A pre
I think both are true, but in doubt the PostgreSQL documentation usually more true than me. However, here I think the PostgreSQL doc might be inaccurate.
It should probably read like this:
Prepared statements only last until it is DEALLOCATEed and no longer than the duration of the current database session.
Without checking I would strongly believe that the JDBC driver deallocates the server-side prepared statement when the JDBC PreparedStatement is closed.