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?

Vladimir Panteleev
  • 24,651
  • 6
  • 70
  • 114
Andreas Selenwall
  • 5,705
  • 11
  • 45
  • 58
  • It has been answered since. Please follow this pattern: http://stackoverflow.com/a/10881260/666414 – maxxyme Aug 02 '13 at 15:29
  • 4
    That is for DB2, I don't think it works for SQL Server, as currentSchema is not listed in the available properties: http://msdn.microsoft.com/en-us/library/ms378988.aspx – Michael Böckling Nov 07 '14 at 11:12

2 Answers2

9

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.

artbristol
  • 32,010
  • 5
  • 70
  • 103
-21

Just give schema=SCHEMANAME

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

Louen
  • 3,617
  • 1
  • 29
  • 49
Dileep
  • 1
  • 1
  • 3
    This example can not work for sql server as it doesn't support schemas in that way, please remove this solution. – Oly Dungey Aug 04 '17 at 14:52