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

How to Correctly Connect to an Oracle Database Using Service Name in JDBC?

DDD
Release: 2024-12-02 06:54:10
Original
445 people have browsed it

How to Correctly Connect to an Oracle Database Using Service Name in JDBC?

Connecting to Oracle with Service Name vs. SID in JDBC

One of the common requirements in Java applications using JDBC is connecting to an Oracle database. In the past, Oracle SID was commonly used for this purpose, but many modern databases now leverage Oracle Service Name instead. This article addresses the issue of connecting to Oracle using Service Name rather than SID in a Java application.

In the provided scenario, the JDBC URL attempts to connect to a database using Oracle Service Name, but it fails. The main challenge is the incorrect syntax for connecting using Service Name.

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

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

Therefore, the corrected URL would be:

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

Alternatively, the Oracle TNS name can also be specified in the JDBC URL, as follows:

jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SID=BLAHSID)(GLOBAL_NAME=BLAHSID.WORLD)(SERVER=DEDICATED)))
Copy after login

By using the correct syntax, the JDBC application can successfully connect to the Oracle database using Service Name.

The above is the detailed content of How to Correctly Connect to an Oracle Database Using Service Name in JDBC?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template