简体   繁体   English

如何远程连接 JDBC

[英]How to connect JDBC remotely

I'm a mac user, I have the oracle database in a virtual machine, and I've been working on it pretty well, I've been installed also Eclipse on my Mac machine, my problem begins now that I need to connect them.我是 Mac 用户,我在虚拟机中有 oracle 数据库,而且我一直在很好地处理它,我的 Mac 机器上也安装了 Eclipse,我的问题现在开始了,我需要连接它们.

Is there any way I can connect to my oracle database remotely with the IP address on the virtual machine?有什么方法可以使用虚拟机上的 IP 地址远程连接到我的 oracle 数据库?

In other words connect my Eclipse installed on mac to my oracle database installed on my windows virtual machine.换句话说,将安装在 mac 上的 Eclipse 连接到安装在 windows 虚拟机上的 oracle 数据库。

Yes, this can be done and is a common scenario for development.是的,这是可以做到的,并且是开发的常见场景。 Depending on the flavour of virtual machine you are using (VMWare, virtualbox, etc) the details will differ, but you will either need to set up port forwarding of the relevant oracle ports onto your host machine (the Mac), or configure bridged networking so the virtual machine with oracle has it's own IP address on the network.根据您使用的虚拟机的风格(VMWare、virtualbox 等),详细信息会有所不同,但您需要在主机(Mac)上设置相关 oracle 端口的端口转发,或者配置桥接网络所以具有 oracle 的虚拟机在网络上有自己的 IP 地址。

I tend to just port forward and use NAT, which means I can connect to the database using the normal jdbc connection string, with the hostname section set to localhost.我倾向于只转发端口并使用 NAT,这意味着我可以使用普通的 jdbc 连接字符串连接到数据库,主机名部分设置为 localhost。 The schematic diagram below should give you a rough idea of what's going on.下面的示意图应该让您大致了解正在发生的事情。

              +--------------------------------------+
              |                                      |
              |                                      |
              |                                      v
              |                              +-------+-----------+
              |                              |                   |
              |                              |   1512            |
+--------------------------------------------+------+-----+------++
|             |            Host Machine (Mac)       | NAT + PortForwarding
|             |                                     |             |
|             |                                     |             |
|             |                                     |             |
|             |                                     |             |
|             |                                     v             |
|             |                              +------+-----------+ |
|             |                              |     1512         | |
|             |                +-------------+------------------+ |
|             |                |                                | |
|   +---------+-------------+  |                                | |
|   |   java application    |  |                                | |
|   |                       |  |                                | |
|   |                       |  |                                | |
|   |db-url=localhost:1512/ |  |            ORACLE VM           | |
|   |                       |  |                                | |
|   |                       |  |                                | |
|   |                       |  |                                | |
|   |                       |  |                                | |
|   +-----------------------+  |                                | |
|                              +--------------------------------+ |
+-----------------------------------------------------------------+

For details on how to set up NAT/portforwding on virtualbox, see this relevant section in this link: https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and-use-it-as-a-server/有关如何在 virtualbox 上设置 NAT/portforwding 的详细信息,请参阅此链接中的相关部分: https://www.howtogeek.com/122641/how-to-forward-ports-to-a-virtual-machine-and -将其用作服务器/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM