How to specify schema for SQL Server in JDBC Spring configuration
Asked Answered
S

3

11

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?

Shogun answered 1/4, 2011 at 6:24 Comment(2)
It has been answered since. Please follow this pattern: https://mcmap.net/q/610929/-how-can-i-set-the-current-schema-for-db2-using-hibernate-jdbcPrajna
That is for DB2, I don't think it works for SQL Server, as currentSchema is not listed in the available properties: msdn.microsoft.com/en-us/library/ms378988.aspxCannibalism
C
10

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.

Clog answered 1/4, 2011 at 10:44 Comment(0)
C
0

I believe that what you want is not really an schema, but a database. If this works for you, you can use the option ....;databaseName= at the jdbc url.

Colombes answered 29/7 at 15:10 Comment(0)
D
-25

Just give schema=SCHEMANAME

For example jdbc:sqlserver://ipaddress:port;database=DBName;schema=SCHEMANAME;selectMethod=cursor;sendStringParametersAsUnicode=false;IntegratedSecurity=true

Dollarbird answered 31/3, 2016 at 14:27 Comment(1)
This example can not work for sql server as it doesn't support schemas in that way, please remove this solution.Sticktight

© 2022 - 2024 — McMap. All rights reserved.