java - How can I specify the current schema for sql server in a jboss data source url? -
i've got sql queries this
select user_id table_user lower(email_address)=? , password=?
the schema application updated don't want update every sql query in application. there way specify current schema jboss connection end?
old connection: jdbc:sqlserver://myserver:1433;databasename=db
tried: jdbc:sqlserver://myserver:1433;databasename=db;currentschema=abc
i tried using currentschema
didn't help, missing object exception when run queries (since assume these looking under dbo). there way around updating queries since know queries run on schema abc
?
these available connection properties microsoft jdbc 4.0 driver. don't see currentschema
in list, , haven't seen driver allows specify particular schema in connection string.
since don't want update sql schema, create synonyms in default (dbo) schema each object. example:
use tempdb; go -- create test schema create schema test authorization dbo; go -- create table in test schema create table test.tablename (columnname int null); -- select tablename in default schema fail select * tablename; go -- create synonym mapping test.tablename dbo.tablename create synonym [dbo].[tablename] [server].[tempdb].[test].[tablename] -- -- select tablename synonym succeed select * tablename; -- cleanup drop synonym [dbo].[tablename]; drop table [test].[tablename]; drop schema [test];
you can use below code generate create synonym
statements user objects. if use it, you'll need update variable values , review statements before executing. no warranty express or implied :)
-- generate create synonym statements user objects declare @fromschema sysname = 'abc', @toschema sysname = 'dbo', @servername sysname = 'server', @databasename sysname = 'database'; select 'create synonym ' + quotename(@toschema) + '.' + quotename(name) + ' ' + quotename(@servername) + '.' + quotename(@databasename) + '.' + quotename(@fromschema) + '.' + quotename(name) + ';' sys.objects is_ms_shipped = 0;
Comments
Post a Comment