user3046703
user3046703

Reputation: 23

Io exception: The Network Adapter could not establish the connection

I am using a tomcat application server and connecting to Oracle DB. There is a file called ojdbc14-10g.jar in the project. In the jsp page I am opening a connection to the database and getting some information. However, when I refresh the page, for many times I get the following error:

java.sql.SQLException:Io exception: The Network Adapter could not establish the connection.

String driverName = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521/xe";
String user = "system";
String password = "1234";
String patientName = null;
String sql1 = "select * from patient where pid=?";
try{
Class.forName(driverName);
con = DriverManager.getConnection(url, user, password);
ps = con.prepareStatement(sql1);
ps.setString(1,patientId);
rs = ps.executeQuery();
if(rs.next()){
    //Some data is coming
}
con.close();
}
    catch(SQLException sqe){
out.println(sqe);
    } 

Also, I am using this code in other jsp pages, and also, for more than four or five refreshes, I am getting the same error.

Could you give me any suggestions?

Upvotes: 2

Views: 52623

Answers (5)

Codemaker2015
Codemaker2015

Reputation: 1

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

This occurs due to the mismatch in Database name or the port is currently used by another service. You can first check the Database name if it is ok then it caused by the port issue or the network adapter could not be started.

It is resolved by executing the following in the command prompt as administrator

netstat -ano | findstr 8080 taskkill /f /pid pid_number

If it could not resolve your issue then it can be solve by the following code

lnsrctl start

enter image description here

Upvotes: 0

Bhushan Shimpi
Bhushan Shimpi

Reputation: 90

Whenever you see a Network Adapter could not establish the connection, you have either the wrong SQL Developer URL or you have a basic SQL*Net connectivity issue! This error is most likely caused by one of these factors:

  • You are using the wrong URL

  • The wrong port number or IP address (or DNS host name) was used

  • The listener is not configured properly

  • The listener process (service) is not running. You can re-start it with the "lsnrctl start" command or on Windows by starting the listener service.

Upvotes: 1

Parvatha
Parvatha

Reputation: 11

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

The above Exception will occur whenever your DB is not reachable. Once your DB is up refresh/bounce your servers and it will resolve the issue.

Upvotes: 1

shakul
shakul

Reputation: 1

just restart your listner services using commands given below.. Starting and Shutting Down the Listener

The Oracle listener is set up to start automatically whenever your server machine is restarted. However, when your system encounters unforeseen circumstances, or when you have manually stopped the listener, you can restart it at the command line. To do so, use the following:

lsnrctl start

You can use Enterprise Manager to stop the listener. To do so, navigate to the Listener: listener_name page by clicking Listener on the Home page. To shut down the listener, click Stop.

You can also stop it at the command line using the following:

lsnrctl stop

Upvotes: 0

santhakr
santhakr

Reputation: 67

The Network Adapter could not establish the connection can happen when the connection url/string is wrong.

The connection string that you use doesn't seem to be right. Should it be jdbc:oracle:thin:@localhost:1521:xe instead of jdbc:oracle:thin:@localhost:1521/xe? (Note that it is ':' instead of '/')

Upvotes: 0

Related Questions