Java JDBC - How to connect to Oracle using Service Name instead of SID

前端 未结 8 1094
醉话见心
醉话见心 2020-11-22 15:14

I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this:

jdbc:oracle:

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 15:25

    http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA

    Thin-style Service Name Syntax

    Thin-style service names are supported only by the JDBC Thin driver. The syntax is:

    @//host_name:port_number/service_name

    For example:

    jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename

    So I would try:

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

    Also, per Robert Greathouse's answer, you can also specify the TNS name in the JDBC URL as below:

    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)))
    

提交回复
热议问题