Connecting to Oracle database installed on one pc to the java application from another machine

旧街凉风 提交于 2019-12-13 07:46:25

问题


I've installed Oracle 12c (desktop class) on my machine, and I can use it via sql developer on the same machine. Now how can I use the same database from another machine (for java application) in the LAN? I tried using the jdbc thin driver as follows: jdbc:oracle:thin:@10.0.11.69:1521:orcl where 10.0.11.69 is my ip address where Oracle is installed. Do i need to install any server where oracle is installed(10.0.11.69) to connect to my db from another machine? I'm trying this from past 3 days and referred to many questions of the same model but none solved my issue. My tnsnames.ora description is as follows:

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))


ORACLR_CONNECTION_DATA =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
    (CONNECT_DATA =
      (SID = CLRExtProc)
      (PRESENTATION = RO)
    )
  )

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

Thanks in advance.


回答1:


You need to connect to PDB if it is a Oracle 12c installation. You can add the following entry in tnsnames.ora:

   pdborcl =
      (DESCRIPTION =
      (ADDRESS = (PROTOCOL=TCP)(HOST=localhost)(PORT=1521))
      (CONNECT_DATA =
        (SERVER = DEDICATED)
        (SERVICE_NAME = pdborcl)
      )
    )

After setting this, the listener needs to be restarted.

lsnrctl stop
lsnrctl start

Then the connect string will be something like this:

jdbc:oracle:thin:@//10.0.11.69:1521/pdborcl

Note the connect string above uses service name instead of SID, because in 12C we need to use service name instead of SID to connect to PDB. Check this post for more details.




回答2:


Java application will not use tnsnames.ora by it's own. You have to call:

System.setProperty("oracle.net.tns_admin", "..path to tnsnames.ora");

To tell the driver where to search for it. Also note, that some tnsnames.ora constructs are not supported by thin driver. For examples the "include" directive.




回答3:


Thanks for the following link, Configuring the connection between client and server Oracle 10g

after researching for a long time I found that I need to add my LAN address(10.0.11.69) in the listener.ora file which solves my problem.

so my listener.ora will looks like this now:

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
        (ADDRESS_LIST=
            (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
            (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.11.69)(PORT = 1521))

        )

    )
  )


来源:https://stackoverflow.com/questions/28535842/connecting-to-oracle-database-installed-on-one-pc-to-the-java-application-from-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!