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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26377764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:33:48  来源:igfitidea点击:

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

javaoraclejdbc

提问by Srinivas Kolla

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 错误:网络适配器无法建立连接

回答by Frank Schmitt

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

您的连接字符串中有一个错字 - 使用localhost而不是loclahost

回答by Frank Schmitt

use localhostin DriverManager.getConnection

localhost在 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();
}

回答by vembutech

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.

如果您的 JDBC 驱动程序无法连接到 oracle,则可能会发生该错误。检查您的 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.

检查侦听器服务是否正在运行

没有防火墙阻止

您的服务正在侦听您在代码中指定的正确端口号。