10

我正在尝试针对以下两个连接到 Oracle DB 的错误来研究此问题:

  1. 封闭连接
  2. java.sql.SQLException:io异常:socket读取超时

我的理解:

  1. 关闭的连接:由于某种网络中断或数据库由于某种“不活动”而关闭会话而发生
  2. java.sql.SQLException:IO异常:套接字读取超时:这是连接成功但由于某种原因套接字/数据为空并最终超时的情况,因为没有数据可用。

是否可以在本地 Oracle DB 环境中复制上述错误?步骤是什么?

感谢您抽出宝贵时间做出回应。

谢谢。

4

2 回答 2

4

您对封闭连接的理解是正确的。关闭连接的原因:防火墙、网络设备和远程数据库监听器等外部设备可以在一段时间不活动后强制关闭网络连接

即使在活动连接上也会发生 ReadTimeOut。如果查询或过程花费大量时间,您将收到读取超时异常。

  • Closed Connection : 在数据库运行时关闭数据库侦听器
  • ReadTimedOut :在程序中添加睡眠超过 10 分钟,并从应用程序调用该程序

Oracle DB env 中 Socket 读取超时错误的复制:

  1. setNetworkTimeout对于 SQL连接// 例如,将超时设置为 120 秒
  2. 从 java 调用数据库过程并在该过程中休眠超过 setNetworkTimeout 的时间

    dbms_lock.sleep(125); -- sleeps for 125 seconds
    

由于由于 125 秒的睡眠,程序在 120 秒内没有返回,java 将在上述情况下抛出套接字读取超时。

于 2015-08-19T04:20:47.633 回答
0

I have just started working with the java.sql.* package, but here is what I understand. A closed connection is an error that occurs and the DB session closes, but no error handling is done so that is the end of it. With java.SQException you can manage this error (use a throws clause) and print it out or do other error handling methods.

Here is a link from Oracle about Exceptions and how to handle them.

Hope this helps.

Exceptions in Java.

于 2013-05-21T21:00:17.467 回答