Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to connect to my friends Oracle server. But while connection I am getting error please help.....

JDBC code

Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
conn=DriverManager.getConnection(jdbc:oracle:thin:@<IPaddress>:<SID>,userName,password);
conn.close();

Error Message

java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:412)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:221)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.wipro.sample.min.main(min.java:28)

    Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
   at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:359)
   at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:422)
   at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:672)
   at oracle.net.ns.NSProtocol.connect(NSProtocol.java:237)
   at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1042)
   at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:301)
   ... 7 more

    Caused by: java.net.ConnectException: Connection refused: connect
   at java.net.PlainSocketImpl.socketConnect(Native Method)
   at java.net.PlainSocketImpl.doConnect(Unknown Source)
   at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.PlainSocketImpl.connect(Unknown Source)
   at java.net.SocksSocketImpl.connect(Unknown Source)
   at java.net.Socket.connect(Unknown Source)
   at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:141)
   at oracle.net.nt.ConnOption.connect(ConnOption.java:123)
   at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:337)
   ... 12 more
share|improve this question

migrated from stackoverflow.com Feb 12 '10 at 8:05

This question came from our site for professional and enthusiast programmers.

    
three words: ping, firewall, network administrator –  Bozho Feb 12 '10 at 6:55
    
@Bozho: so what should i do on my friends system to enable the connection... –  Hari Feb 12 '10 at 6:59
    
did you ping? did you check the firewall? –  Bozho Feb 12 '10 at 7:01
    
i pinged the system.. there was no problem...what i have to check in the firewall –  Hari Feb 12 '10 at 7:03
1  
BTW, it should be Class.forName ("oracle.jdbc.driver.OracleDriver"); –  Pascal Thivent Feb 12 '10 at 7:33

4 Answers 4

up vote 1 down vote accepted

Looks like oracle server is not listening...

Connect to the machine where oracle is present..

Run su - oracle

lsnrctl status

is listner is not active then do lsnrctl start

share|improve this answer

A typical Oracle network setup consists of:

  1. The database instance on the server
  2. As @Abhiram states, a "listener" also runs on the server, waiting for connections, by default on port 1521.
  3. Clients connect to the server on the correct port, the listener hands off the connection to the database instance.

As others have pointed out, (1) the database needs to be up; (2) the listener needs to be running and you need to know what port; (3) firewalls need to be configured to allow traffic on the port, most often on the server side.

Can your friend use an ODBC connection on their system, by way of the listener (not a local connection)? In other words, would your code run on their system?

share|improve this answer

It seems like you can't connect to Oracle server. First try to telnet your Oracle server by using the Oracle's port.

Ex: telnet <Oracle Serrver IP> 1521

share|improve this answer
    
Connecting To <ipaddress> Could not open connection to the host, on port 1521: Connect failed –  Hari Feb 12 '10 at 7:10
    
above was the message i recieved when i executed the provided statement –  Hari Feb 12 '10 at 7:11
    
Your oracle server is refusing to connect with your application. Please check firewall configuration in the Oracle server also make sure whether Oracle server is up and running. –  Upul Feb 12 '10 at 7:14
    
how to check the firewall configaration..... –  Hari Feb 12 '10 at 7:18
    
Please follow this tutorial windowsecurity.com/articles/Customizing-Windows-Firewall.html –  Upul Feb 12 '10 at 7:26

This error may occure when you:

  1. Try to connect to the different host:port. Double-check your settings.
  2. Oracle server is down. You need to start it.
  3. Your firewall blocks your connection to oracle. You need to allow access for your application.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.