0

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
Hariharbalaji
  • 103
  • 1
  • 1
  • 3

5 Answers5

2

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

1

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

Upul
  • 211
  • 1
  • 2
  • 6
  • Connecting To Could not open connection to the host, on port 1521: Connect failed –  Feb 12 '10 at 07:10
  • above was the message i recieved when i executed the provided statement –  Feb 12 '10 at 07: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 07:14
  • how to check the firewall configaration..... –  Feb 12 '10 at 07:18
  • Please follow this tutorial http://www.windowsecurity.com/articles/Customizing-Windows-Firewall.html – Upul Feb 12 '10 at 07:26
  • Add an exception rule for Oracle server – Upul Feb 12 '10 at 07:27
1

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.
uthark
  • 113
  • 5
0

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?

DCookie
  • 2,098
  • 1
  • 17
  • 18
-1

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:@<IPaddress>:<SID>,userName,password);
    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();
Sven
  • 98,649
  • 14
  • 180
  • 226
  • This question has been answered nearly 5 years ago and the solution was something else entirely. – Sven Dec 29 '14 at 20:20