简体   繁体   English

java.sql.SQLRecoverableException:网络适配器无法建立连接

[英]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.

相关问题 java.sql.SQLException:网络适配器无法建立连接 - java.sql.SQLException: The Network Adapter could not establish the connection 网络适​​配器无法建立连接 - The network adapter could not establish the connection java.sql.SQLException: IO 异常:网络适配器无法建立连接? - java.sql.SQLException: IO Exception : The Network adapter could not establish the connection? 获取“ java.sql.SQLException:Io异常:网络适配器无法建立连接” - Getting “java.sql.SQLException: Io exception: The Network Adapter could not establish the connection” Java:Io异常:网络适配器无法建立连接 - Java : Io exception: The Network Adapter could not establish the connection java.sql.SQLException:Io异常:网络适配器无法建立连接 - java.sql.SQLException: Io exception: The Network Adapter could not establish the connection java.sql.SQLRecoverableException:控制台/管理员命令已从管理上禁用了连接 - java.sql.SQLRecoverableException: Connection has been administratively disabled by console/admin command java.sql.SQLRecoverableException:使用连接池时是否没有更多数据要从套接字读取? - java.sql.SQLRecoverableException: No more data to read from socket when using a connection pool? 数据库连接问题 - 引起:java.sql.SQLRecoverableException:IO 错误:指定的主机未知 - Database connection problem - Caused by: java.sql.SQLRecoverableException: IO Error: Unknown host specified 如何解决 java.sql.SQLRecoverableException:IO 错误:连接超时 - How to resolve java.sql.SQLRecoverableException: IO Error: Connection timed out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM