[英]java.sql.SQLRecoverableException: The Network Adapter could not establish the connection
Here's the code I'm using (Oracle database connectivity): 这是我正在使用的代码(Oracle数据库连接):
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
java.sql.SQLRecoverableException:IO错误:网络适配器无法建立连接
您的连接字符串中有错别字-使用localhost
而不是loclahost
use localhost
in DriverManager.getConnection 在DriverManager.getConnection中使用
localhost
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. 如果您的JDBC驱动程序无法连接到oracle,则可能发生该错误。 Check if your oracle service is running and no firewall is blocking your connection.
检查您的oracle服务是否正在运行,并且没有防火墙阻止您的连接。
Check if oracle is listening in port 1521 or not, if not fix the port issue and then try connecting to your database. 检查oracle是否正在侦听端口1521,如果无法解决端口问题,请尝试连接到数据库。
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.
您的服务正在侦听代码中指定的正确端口号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.