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

JDBC code


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

5 Answers 5


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


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

  • Connecting To <ipaddress> Could not open connection to the host, on port 1521: Connect failed
    – Hari
    Feb 12, 2010 at 7:10
  • above was the message i recieved when i executed the provided statement
    – Hari
    Feb 12, 2010 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, 2010 at 7:14
  • how to check the firewall configaration.....
    – Hari
    Feb 12, 2010 at 7:18
  • Please follow this tutorial windowsecurity.com/articles/Customizing-Windows-Firewall.html
    – Upul
    Feb 12, 2010 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.

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?


Gusset do following:

  1. ping ip address. If get time out , it means there is network connection problem.
  2. If ping result indicates connection ok, and the still get same exception, then do: use command tracert Ip Address to gat domain name.
  3. use domain name instead of ip addesss in your connection string:

    conn=DriverManager.getConnection(jdbc:oracle:thin:@<domain Name>:<SID>,userName,password);
  4. use DriverManager.registerDriver (new oracle.jdbc.OracleDriver()); instead of Class.forName(oracle.jdbc.driver.OracleDriver).newInstance();
  • This question has been answered nearly 5 years ago and the solution was something else entirely.
    – Sven
    Dec 29, 2014 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .