I have Windows 7 installed on my laptop which has VMware Workstation with Oracle Linux 5.5. 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. So then I run this java code on Windows:
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. Here is the picture with my settings for Virtual Network Editor in VMWare and network configurations on Linux:
http://i.cubeupload.com/vAen5q.jpg
On Linux I also have:
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:
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:
connection.setUrl("jdbc:oracle:thin:@IPv4Address:1521:xe");
connection.setUser("example");
connection.setPassword("pass");
When you complete the all the steps you can connect from your host to the Database in your virtual machine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.