java – IO Error: The Network Adapter could not establish the connection

java – IO Error: The Network Adapter could not establish the connection

Either:

  1. The database isnt running
  2. You got the URL wrong
  3. There is a firewall in the way.

(This strange error message is produced by Oracles JDBC driver when it cant connect to the database server. Network adapter appears to refer to some component of their code, which isnt very useful. Real network adapters (NICs) dont establish connections at all: TCP protocol stacks do that. It would have been a lot more useful if they had just let the original ConnectException be thrown, or at least used its error message and let it appear in the stack trace.)

I had the same problem, and this is how I fixed it.
I was using the wrong port for my connection.

private final String DB_URL  = jdbc:oracle:thin:@localhost:1521:orcll; // 1521 my wrong port
  • go to your localhost
  • (my localhost address) : https://localhost:1158/em

  • login

    • user name
    • password
    • connect as –> normal
  • Below General click on LISTENER_localhost

  • look at you port number
    • Net Address (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1522))
      Connect to port 1522
  • Edit you connection
    change port 1521 to 1522.

    • done

java – IO Error: The Network Adapter could not establish the connection

Another thing you might want to check that the listener.ora file matches the way you are trying to connect to the DB. If you were connecting via a localhost reference and your listener.ora file got changed from:

HOST = localhost

to

HOST = 192.168.XX.XX

then this can cause the error that you had unless you update your hosts file to accommodate for this. Someone might have made this change to allow for remote connections to the DB from other machines.

Leave a Reply

Your email address will not be published.