Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify schema for SQL Server in JDBC Spring configuration

We are using the org.apache.commons.dbcp.BasicDataSource as parent class for our datasources in Spring.

Is it possible to specify which schema to use in either the "url" or in another property in the DBCP datasource?

like image 221
Andreas Selenwall Avatar asked Apr 01 '11 06:04

Andreas Selenwall


People also ask

How do I select a schema in SQL Server?

You can get a list of the schemas using an SSMS or T-SQL query. To do this in SSMS, you would connect to the SQL instance, expand the SQL database and view the schemas under the security folder. Alternatively, you could use the sys. schemas to get a list of database schemas and their respective owners.

How configure JDBC SQL Server?

Connect to SQL Server Using JDBC Driver and Command Line datasource = "MSSQLServerAuth"; username = ""; password = ""; conn = database(datasource,username,password); Or, to connect without Windows authentication, use the configured JDBC data source and specify the user name username and the password pwd .

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

We can use JDBC URL to specify all kinds of parameters during connection setup. The usual parameters are database type, address, port, database name, etc. Since Postgres version 9.4. there is added support for specifying the current schema using URL.

What is the JDBC connection string for SQL Server?

jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]] where: jdbc:sqlserver:// (Required) is known as the subprotocol and is constant. serverName (Optional) is the address of the server to connect to.


1 Answers

I don't think it's possible to specify the schema since this is a function of the user, not the JDBC session. You should probably create a user with their default schema set to each schema you want to use, and then specify the user in the dbcp configuration.

like image 148
artbristol Avatar answered Oct 21 '22 11:10

artbristol