Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify the schema when connecting to postgres with JDBC?

Is it possible? Can i specify it on the connection URL? How to do that?

like image 529
marcosbeirigo Avatar asked Nov 12 '10 20:11

marcosbeirigo


People also ask

How do I create a schema in JDBC connection?

there is added support for specifying the current schema using URL. With @ClassRule, we create an instance of PostgreSQL database container. Next, in the setup method, create a connection to that database and create the required objects. To change the default schema, we need to specify the currentSchema parameter.


2 Answers

I know this was answered already, but I just ran into the same issue trying to specify the schema to use for the liquibase command line.

Update As of JDBC v9.4 you can specify the url with the new currentSchema parameter like so:

jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema 

Appears based on an earlier patch:

http://web.archive.org/web/20141025044151/http://postgresql.1045698.n5.nabble.com/Patch-to-allow-setting-schema-search-path-in-the-connectionURL-td2174512.html

Which proposed url's like so:

jdbc:postgresql://localhost:5432/mydatabase?searchpath=myschema 
like image 116
Hiro2k Avatar answered Oct 21 '22 05:10

Hiro2k


As of version 9.4, you can use the currentSchema parameter in your connection string.

For example:

jdbc:postgresql://localhost:5432/mydatabase?currentSchema=myschema 
like image 21
Steve Avatar answered Oct 21 '22 06:10

Steve