简体   繁体   English

获取“ java.sql.SQLException:Io异常:网络适配器无法建立连接”

[英]Getting “java.sql.SQLException: Io exception: The Network Adapter could not establish the connection”

The below is my code. 下面是我的代码。 I wanted to connect to Employee table from Oracle. 我想从Oracle连接到Employee表。

public static void main(String[] args) {         
    try {
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
        Statement statement = connection.createStatement();
        ResultSet resultset = statement.executeQuery("select 'Connected' from dual");
        resultset.next();
        String s = resultset.getString(1);
        System.out.println(s);
        statement.close();
        connection.close();
    } catch (Exception e) {
        System.out.println("The exception raised is:" + e);
    }
}

I am always getting the error as "The exception raised is:java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" 我总是收到错误消息,因为“引发的异常是:java.sql.SQLException:Io异常:网络适配器无法建立连接”

I tried turning off the firewall, but no luck. 我尝试关闭防火墙,但是没有运气。 Could someone please help me in resolving the issue. 有人可以帮我解决问题。

Did you try telnet'ing that db? 您是否尝试过远程登录该数据库? something like... 就像是...

Telnet localhost 1521

Just to check if there is a process listing to that port. 仅检查该端口是否有进程列表。

It can be three thins: 它可以是三个瘦:

  1. The Database is not running or doesn't exist 数据库未运行或不存在
  2. The URL you have is invalid 您输入的网址无效
  3. The Database is running in different Port. 数据库在其他端口中运行。
  4. You have a firewall( In this case can't be because you already check that) 您有防火墙(在这种情况下不可能是因为您已经检查过)

Ok, when My team was in a black box server with an url for connecting to the Database we didn't know what was the error and so we created a UDL File that can make this test. 好的,当我的团队位于黑匣子服务器中,该URL带有用于连接数据库的URL时,我们不知道发生了什么错误,因此我们创建了可以进行此测试的UDL文件 Check this tutorial for connection testing With that you can test the three of them and see if you have a real connection with the Database. 查看本教程进行连接测试。使用该教程,您可以测试它们中的三个,并查看是否与数据库建立了真正的连接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException: IO 异常:网络适配器无法建立连接? - java.sql.SQLException: 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 无法连接到Oracle DB,因为java.sql.SQLException而出现错误:Io异常:网络适配器无法建立连接 - Not able to connect to Oracle DB getting error as java.sql.SQLException: Io exception: The Network Adapter could not establish the connection java.sql.SQLException:网络适配器无法建立连接 - java.sql.SQLException: The Network Adapter could not establish the connection SQLException:Io异常:网络适配器无法建立连接 - SQLException: Io exception: The Network Adapter could not establish the connection Java:Io异常:网络适配器无法建立连接 - Java : Io exception: The Network Adapter could not establish the connection 无法创建 PoolableConnectionFactory(Io 异常:网络适配器无法建立连接) - Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection) 出现IO错误:网络适配器无法建立连接 - getting IO Error: The Network Adapter could not establish the connection 异常:网络适配器无法在简单的jdbc程序中建立连接 - getting exception: The Network Adapter could not establish the connection in simple jdbc program 获取异常:网络适配器无法在简单的 jdbc 程序中建立连接 - getting exception: The Network Adapter could not establish the connection in simple jdbc program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM