Java IO 错误:套接字读取超时。原因是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24011258/
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-08-14 09:43:13  来源:igfitidea点击:

IO Error: Socket read timed out. What are the reasons?

javaoraclejdbc

提问by user2795559

My simplified code (which demonstrates that the connection breaks with error "IO Error: Socket read timed out"):

我的简化代码(它表明连接因错误“IO 错误:套接字读取超时”而中断):

    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    this.connection = DriverManager.getConnection("jdbc:oracle:thin:@", properties);
    while(isStarted){
        this.statement = this.connection.createStatement();
        ResultSet result = this.statement.executeQuery("select sysdate from dual");
        result.next();
        System.out.println("Sysdate: " + result.getString(1));
        result.close();
        this.statement.close();
        this.statement = null;
        TimeUnit.SECONDS.sleep(4);
    }
    this.connection.close();
    this.connection = null;

after 4-5 hours i catched:

4-5 小时后,我发现:

 IO Error: Socket read timed out
    java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:886)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1491)
at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:406)

What are the reasons? how to solve this problem?

原因是什么?如何解决这个问题呢?

回答by Prakhar Singh

I had the same problem. Check your services and see to it that only OracleServiceXE and Oracle XETNSListener is running.

我有同样的问题。检查您的服务并确保只有 OracleServiceXE 和 Oracle XETNSListener 正在运行。

You can crosscheck it in cmd by using command

您可以使用命令在 cmd 中对其进行交叉检查

netstat -ano | find "1521"

netstat -ano | 找到“1521”

In the result the last column shows the PID and it should be unique. If the command returns no result then your Listener is not running.

在结果中,最后一列显示 PID,它应该是唯一的。如果该命令没有返回结果,那么您的监听器没有运行。