Home >Java >javaTutorial >Can I Specify a Specific Schema for JDBC Connections to PostgreSQL?
Question:
Is there a way to specify the desired database schema when establishing JDBC connections to a Postgres database?
Answer:
Yes, it is possible to specify the target schema in the JDBC connection URL.
Version 9.4 and Above:
As of JDBC version 9.4, the currentSchema parameter can be used in the connection URL to specify the schema:
jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema
Earlier JDBC Versions:
For earlier versions of JDBC, you can use the searchpath parameter in the connection URL:
jdbc:postgresql://localhost:5432/mydatabase?searchpath=myschema
This URL format allows you to specify the schema to use for database operations within that connection.
The above is the detailed content of Can I Specify a Specific Schema for JDBC Connections to PostgreSQL?. For more information, please follow other related articles on the PHP Chinese website!