So I have created a few schema in H2. How can I connect to a specific schema in H2
For example when I need to connect to a specific schema in SQL Server I have below JDBC URL
jdbc:sqlserver://HOSTNAME:PORT;SelectMethod=cursor;instanceName=MYSCHEMA;databaseName=DBNAME
Is this feature available in H2. If not is there a workaround.
I do not want to always access a particular table in my schema instance be accessed like MYSCHEMA.TABLE_NAME
Otherwise I suppose only way out will be to create all table into the default schema that is public
There is a setDefaultSchemaName() method on the Database object that you can use to set a different default schema.
Example. In this example, let us create a schema named test_schema under SA user, using the following command. CREATE SCHEMA test_schema AUTHORIZATION sa; The above command produces the following output.
As per documentation, default JDBC connection string is jdbc:h2:~/test. And, for TCP connection jdbc:h2:tcp://localhost/~/test.
There is such feature supported. See this:
http://www.h2database.com/html/grammar.html#set_schema
You can specify the schema in the connection string:
jdbc:h2:test;SCHEMA=SCHEMA_NAME
You can also change the current schema with:
SET SCHEMA SCHEMA_NAME;
Hope this helps.
SET SCHEMA_SEARCH_PATH shemaName
http://h2database.com/html/grammar.html?highlight=drop%2Calias&search=drop%20alias#set_schema_search_path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With