-2

why in getConnection() method, localhost accept @localhost and it accept //localhost why and what is the difference between @localhost and //localhost .

i.e,

Connection 
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",
"system","system");
  • The SID based URL syntax `@localhost:1521:XE` has been [deprecated](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/jjdbc/data-sources-and-URLs.html#GUID-6F729E4D-064B-4FD9-AE92-1BD44B8BE5EF) since Oracle 10 –  Nov 13 '18 at 10:38

1 Answers1

2

The format of the JDBC connection string depends on the database vendor or driver (apart from the jdbc: prefix and the requirement of having at least three separated-by-colons fields - see here).

In the case of Oracle, and specifically its "thin" driver, there are several syntaxes, depending on whether you use the Service Name or the SID

In short, if using Service Name you write

jdbc:oracle:thin:@//host_name:port_number/service_name

where host_name can be localhost.

If using SID you write instead

jdbc:oracle:thin:@host_name:port_number:sid_number

Your example corresponds to this latter case.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • 1
    The syntax with the SID is deprecated since Oracle 10. The [manual](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/jjdbc/data-sources-and-URLs.html#GUID-44572C63-10D2-478A-BB2E-ACF6674C59CC) doesn't even list it as a possibility any more. –  Nov 13 '18 at 10:31