问题
I have installed Oracle 11g on my system and i am able to connect to database using simple java program.
ORACLE_USER = "user1"
ORACLE_PASSWORD = "user1"
ORACLE_HOST = "localhost"
ORACLE_SID = "ORCL"
ORACLE_PORT = "1521 "
String connectionString = "jdbc:oracle:thin:@(description=(address=(host=" + ORACLE_HOST
+ ")(protocol=tcp)(port=" + ORACLE_PORT + "))(connect_data=(sid=" + ORACLE_SID + ")))";
Connection connection = DriverManager.getConnection(connectionString, ORACLE_USER,ORACLE_PASSWORD);
Now, I want to connect my team mates system's database(LAN network). I am able to ping that system. The Only change i did in above code is
ORACLE_HOST = "kdsystem" //machine name
but same code fails and showing following error message:
java.sql.SQLException: Io exception: The Network Adapter could not establish the
connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
414)
......
....
Please help me to resolve this issue. Thanks.
回答1:
On your team mate machine you can check with netstat or other tool if it is listening on ORACLE_PORT and on ORACLE_HOST (IP adress visible to your machine, or 0.0.0.0). You can check it on Linux/unix machine with:
netstat -an | grep 1521
or on Windows machine where grep
is not available:
netstat -an | findstr 1521
Show us results of such command.
If Oracle is listening on localhost (127.0.0.1) then other machines cannot connect with it. You will have to configure Oracle server to address available to others.
If Oracle is listening on address available to other machines, then check if you can connect to that machine using telnet. If it cannot connect with Oracle then probably there is firewall or similar blockade between those two machines.
来源:https://stackoverflow.com/questions/12002285/how-to-connect-to-an-oracle-db-from-another-system