【问题标题】:java.sql.SQLRecoverableException: The Network Adapter could not establish the connectionjava.sql.SQLRecoverableException:网络适配器无法建立连接
【发布时间】:2014-10-15 08:19:28
【问题描述】:

这是我正在使用的代码(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();

出现以下错误:

java.sql.SQLRecoverableException:IO 错误:网络适配器可以 没有建立连接

【问题讨论】:

  • 欢迎来到 StackOverflow。你能告诉我们你的堆栈跟踪吗?没有这个就很难确定你的具体问题。

标签: java oracle jdbc


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    在 DriverManager.getConnection 中使用 localhost

    代码如下:

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

    【讨论】:

      【解决方案3】:

      如果您的 JDBC 驱动程序无法连接到 oracle,则可能会发生该错误。检查您的 oracle 服务是否正在运行并且没有防火墙阻止您的连接。

      检查oracle是否正在监听1521端口,如果没有解决端口问题,然后尝试连接到您的数据库。

      要检查的东西,

      检查监听服务是否正在运行

      没有防火墙阻止

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-10-28
        • 1970-01-01
        • 2013-08-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多