Home >Java >javaTutorial >JDBC to Oracle: SID vs. Service Name—Which Connection String Should I Use?
JDBC Connection to Oracle: Using Service Name vs. SID
When connecting to Oracle databases using JDBC, there are two main approaches: using the Oracle System Identifier (SID) or the Service Name. The original connection used the SID, but the new requirement involves connecting using the Service Name instead. However, the initial attempt led to connection issues.
Solution
To resolve the issue, the correct syntax for connecting using the Service Name is:
jdbc:oracle:thin:@//host_name:port_number/service_name
Applying this syntax, the new connection string becomes:
jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD
where "ABCD" represents the Service Name of the target database.
Alternative Approach
Alternatively, the connection can also be established by specifying the Transaction Network Service (TNS) name within the JDBC URL:
jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(TNS=BLAHSID)(SERVER=DEDICATED)))
The above is the detailed content of JDBC to Oracle: SID vs. Service Name—Which Connection String Should I Use?. For more information, please follow other related articles on the PHP Chinese website!