views:

736

answers:

2

I'd like to set default database schema in Oracle Connection URL

jdbc:oracle:thin:@<server>:<port1521>:<sid>

My sample SQL statement:

select monkey_name from animals.monkey

I need to query database without schema prefix anymals. i.e. when I run this statement

select monkey_name from monkey

it will uses animals schema by default.

What do I need to specify in connection URL above get such effect?

Thanks

+5  A: 

You can't put anything in the connection URL.

In Oracle each user has their own schema (even if doesn't contain any objects) and that is their default schema. Once logged in/connected, they can change their default schema with an

ALTER SESSION SET CURRENT_SCHEMA=animals

So you'd need to do the extra statement after connecting. It is possible to have a logon trigger on the user and/or database that will run this when they log in. I'd personally prefer an explicit statement when an application connects.

Gary
This looks like something I can work around it. Create logon trigger with this statement might be my possible solution.Thanks.
manetic
I can now see that, this should be a solution. By having this logon trigger, I don't have to modify my sql. So all generic statements are still portable.
manetic
+1  A: 

What about the use of synonyms?

create synonym monkey for animals.monkey;

select monkey_name from monkey
Rene
It's a good idea. However I find it is not definite, I am not sure if there are any side effects that could break things along the way.
manetic
+This solution is quite commonly used and works well.
Jeffrey Kemp