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