Skip to Main Content
  • Questions
  • What does "//" in jdbc connection string mean?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Marcin.

Asked: September 19, 2016 - 11:00 am UTC

Last updated: September 19, 2016 - 4:32 pm UTC

Version: 11gr2

Viewed 1000+ times

You Asked

Hi AskTom team.

I'm testing a jdbc connection to database in my java application. When I use the following form:

jdbc:oracle:thin:@myhost:1521/myservicename


everything's fine, my java application connects to the db.

When I try to use this form

jdbc:oracle:thin:@//myhost:1521/myservicename


I'm getting: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

However if I change it a little and add .world domain

jdbc:oracle:thin:@//myhost:1521/myservicename.world


everything's fine again. So my question is: what does this double forward slash do? Why isn't the default domain (.world) used when I'm connecting to //myhost? Or why is it used if I remove the slashes?

Thanks!
Marcin

and Connor said...

Thats interesting - I was unaware that

jdbc:oracle:thin:@myhost:1521/myservicename

was even valid syntax. I'll give you my hypothesis but I can't guarantee its accuracy.

As I'm sure you know, you can connect with a tns entry, eg

@my_tns_name

but that is just a short hand for a true description, ie, there is nothing to stop you from doing (for example):

connect user/pass@"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=sales.us.acme.com)))"

In these cases, we are still using the standard connection mechanisms, so we'll respect entries in sqlnet.ora (like default domain) etc.

So my hypothesis is:

@myhost:1521/myservicename

is sufficient information to connect using the standard connection vehicle (so we still look in sqlnet.ora etc for default domain).

Conversely, the '//' syntax is known as "ezconnect" and is specifically designed for when there is NO tnsnames etc... So the entire connection information is gleaned solely from what is on that line. Hence the service name must be fully qualified because we arent going to visit sqlnet.ora (which might not even exist) to look for things like default domains etc.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Sure that helps

Marcin Wroblewski, September 20, 2016 - 6:53 am UTC

Your hypothesis sounds very reasonable. Thanks for your insight