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
You've got a typo in your connection string - use localhost
instead of loclahost
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();
}
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.