Srinivas Kolla
Srinivas Kolla

Reputation: 1

java.sql.SQLRecoverableException: The Network Adapter could not establish the connection

Here's the code I'm using (Oracle database connectivity):

try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@loclahost:1521:XE","system","system");
        System.out.println("connection is established");
        Statement stmt=conn.createStatement();
        int i=stmt.executeUpdate("insert table students ( name varchar2(15),mobile number(10),age varchar2(1))");
        System.out.println("Save Sucessfully");
        stmt.close();
        conn.close();
} catch(Exception e) {
    System.out.println(e);
}
this.dispose();

Getting following Error:

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

Upvotes: 0

Views: 17435

Answers (3)

user4416597
user4416597

Reputation:

use localhost in DriverManager.getConnection

Here is the code :

try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
    System.out.println("connection is established");
    Statement stmt=conn.createStatement();
    int i=stmt.executeUpdate("insert table students ( name varchar2(15),mobile number(10),age varchar2(1))");
    System.out.println("Save Sucessfully");
    stmt.close();
    conn.close();
  }
  catch(Exception e) {
  System.out.println(e);
 }
  this.dispose();
}

Upvotes: 2

BDRSuite
BDRSuite

Reputation: 1612

The error could occur if your JDBC driver is unable to connect to oracle. Check if your oracle service is running and no firewall is blocking your connection.

Check if oracle is listening in port 1521 or not, if not fix the port issue and then try connecting to your database.

Collectively the things to check ,

Check if the listener service is running

No firewall is blocking

Your service is listening on the correct port number that you specified in your code.

Upvotes: 0

Frank Schmitt
Frank Schmitt

Reputation: 30775

You've got a typo in your connection string - use localhost instead of loclahost

Upvotes: 3

Related Questions