Home > Java > javaTutorial > How to Connect to an Oracle Database Using a Service Name in Java?

How to Connect to an Oracle Database Using a Service Name in Java?

Linda Hamilton
Release: 2024-12-03 14:43:10
Original
673 people have browsed it

How to Connect to an Oracle Database Using a Service Name in Java?

Connecting to Oracle Using Service Name in Java

In Java, connecting to an Oracle database typically involves specifying the hostname, port, and Oracle SID. However, some Oracle databases use a "Service Name" instead of SID. To connect to such a database, a slight modification in the JDBC URL is required.

The correct syntax for connecting to Oracle using a Service Name is:

jdbc:oracle:thin:@//host_name:port_number/service_name
Copy after login

For example, if the hostname is "oracle.example.com", the port number is 1522, and the Service Name is "ABCD," the JDBC URL would be:

jdbc:oracle:thin:@//oracle.example.com:1522/ABCD
Copy after login

In case the JDBC URL includes a TNS name, the syntax would be:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=host_name)(PORT=port_number)))(CONNECT_DATA=(SERVICE_NAME=<service_name>)))
Copy after login

For instance, if the TNS name is "BlahSID," the JDBC URL would be:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=BlahSID)))
Copy after login

The above is the detailed content of How to Connect to an Oracle Database Using a Service Name in Java?. 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