Home > Java > javaTutorial > JDBC to Oracle: SID vs. Service Name—Which Connection String Should I Use?

JDBC to Oracle: SID vs. Service Name—Which Connection String Should I Use?

Linda Hamilton
Release: 2024-12-02 18:21:14
Original
1073 people have browsed it

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
Copy after login

Applying this syntax, the new connection string becomes:

jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD
Copy after login

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)))
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template