[英]Unable to connect to Oracle 11g on virtual machine via JDBC: Connection reset
I have Windows 7 installed on my laptop which has VMware Workstation with Oracle Linux 5.5. 我在装有VMware Workstation和Oracle Linux 5.5的笔记本电脑上安装了Windows 7。 There is Oracle 11g r2 database on Linux and I need to estabilish the connection via JDBC from host(Win7) to database on guest system(Linux) using NAT. Linux上有Oracle 11g r2数据库,我需要使用NAT建立从主机(Win7)到来宾系统(Linux)上通过JDBC的JDBC连接。 So then I run this java code on Windows: 因此,我在Windows上运行了以下Java代码:
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection con;
try{
con = DriverManager.getConnection("jdbc:oracle:thin:@172.68.0.1:1521:orcl", "system","oracle");
} catch (SQLException e) {
e.printStackTrace();
}
}
I get this exception: 我得到这个例外:
java.sql.SQLRecoverableException: I/O Exception: Connection reset
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:428)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at OracleTest.main(OracleTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at oracle.net.ns.Packet.receive(Packet.java:283)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:287)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1054)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)
... 12 more
On Windows I assigned IPv4-address 172.68.0.1 to VMware Network Adapter VMnet8. 在Windows上,我为VMware Network Adapter VMnet8分配了IPv4地址172.68.0.1。 Here is the picture with my settings for Virtual Network Editor in VMWare and network configurations on Linux: 这是我在VMWare中为Virtual Network Editor设置以及在Linux上的网络配置的图片:
http://i.cubeupload.com/vAen5q.jpg http://i.cubeupload.com/vAen5q.jpg
On Linux I also have: 在Linux上,我还有:
listener.ora: listener.ora中:
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.68.0.1)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /u01/app/oracle
tnsnames.ora: tnsnames.ora中:
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.68.0.1)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
So I need to find out what's the problem and how to solve it. 因此,我需要找出问题所在以及如何解决。 Please, help. 请帮忙。
It's late, but I found a solution for this. 已经很晚了,但是我找到了解决方案。
In Java you can use this: 在Java中,您可以使用以下命令:
connection.setUrl("jdbc:oracle:thin:@IPv4Address:1521:xe"); connection.setUrl( “JDBC:预言:瘦:@ IPv4Address:1521:XE”);
connection.setUser("example"); connection.setUser( “例如”);
connection.setPassword("pass"); connection.setPassword( “通”);
When you complete the all the steps you can connect from your host to the Database in your virtual machine. 完成所有步骤后,您可以从主机连接到虚拟机中的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.