In my Java program I have to call a stored prodedure called FooBar(null) . The program tries to be db platform independent. Some SQL statements are put together programmatically, one of them is:
insert into foo_bar (id, user, timestmp) values (1, 'foo', FooBar(null));
This works on Oracle, HSLQDB, MySQL. Now I have to make it work on MSSQL. I created the FooBar function. I log into the database with a user that has the default schema called foo.
This statement works only if I put the schema name before the function name:
insert into foo_bar (id, user, timestmp) values (1, 'foo', foo.FooBar(null));
If I log into the database then exec FooBar(null) works without foo.
Do you know how to avoid this foo. on MSSQL?
Unfortunately, unlike almost all other objects, DB functions must be fully qualified with the schema name in T-SQL.
If you’re putting the statement together programmatically though, you can hack it to see if the JDBC driver is MSSQL and in that case, add the schema name.