Oracle JDBC间歇性连接问题

编程入门 行业动态 更新时间:2024-10-24 10:28:21
本文介绍了Oracle JDBC间歇性连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了一个非常奇怪的问题这是一个非常简单的JDBC连接到Oracle数据库的使用

I am experiencing a very strange problem This is a very simple use of JDBC connecting to an Oracle database

OS: Ubuntu Java Version: 1.5.0_16-b02 1.6.0_17-b04 Database: Oracle 11g Release 11.1.0.6.0

当我使用jar文件时 OJDBC14.jar 它连接到每次数据库当我使用jar文件时 OJDBC5.jar 它会连接几次,有时会抛出错误(如下所示)如果我使用Java 6重新编译并使用 OJDBC6.jar 我得到的结果与 OJDBC5.jar

When I make use of the jar file OJDBC14.jar it connects to the database everytime When I make use of the jar file OJDBC5.jar it connects some times and other times it throws an error ( shown below) If I recompile with Java 6 and use OJDBC6.jar I get the same results as OJDBC5.jar

我需要JODB5.jar中的特定功能,这些功能在OJDBC14.jar中不可用

I need specific features in JODB5.jar that are not available in OJDBC14.jar

任何想法

错误

> Connecting to oracle java.sql.SQLException: Io exception: Connection reset at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:74) at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:494) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474) at java.sql.DriverManager.getConnection(DriverManager.java:525) at java.sql.DriverManager.getConnection(DriverManager.java:171) at TestConnect.main(TestConnect.java:13)

代码

以下是我正在使用的代码

Below is the code I am using

import java.io.*; import java.sql.*; public class TestConnect { public static void main(String[] args) { try { System.out.println("Connecting to oracle"); Connection con=null; Class.forName("oracle.jdbc.driver.OracleDriver"); con=DriverManager.getConnection( "jdbc:oracle:thin:@172.16.48.100:1535:sample", "JOHN", "90009000"); System.out.println("Connected to oracle"); con.close(); System.out.println("Goodbye"); } catch(Exception e) { e.printStackTrace(); } } }

推荐答案

在某些OTN论坛中提供了解决此问题的解决方案( https: //kr.forums.oracle/forums/thread.jspa?messageID=3699989 )。但是,没有解释问题的根本原因。以下是我尝试解释问题的根本原因。

There is a solution provided to this problem in some of the OTN forums (kr.forums.oracle/forums/thread.jspa?messageID=3699989). But, the root cause of the problem is not explained. Following is my attempt to explain the root cause of the problem.

Oracle JDBC驱动程序以安全的方式与Oracle服务器通信。驱动程序使用 java.security.SecureRandom 类来收集熵以确保通信安全。此类依赖于本机平台支持来收集熵。

The Oracle JDBC drivers communicate with the Oracle server in a secure way. The drivers use the java.security.SecureRandom class to gather entropy for securing the communication. This class relies on the native platform support for gathering the entropy.

熵是由操作系统或应用程序收集/生成的随机性在密码学或其他需要随机数据的用途中。这种随机性通常从硬件源收集,可以是硬件噪声,音频数据,鼠标移动或专门提供的随机生成器。内核收集熵并存储它是一个熵池,并通过特殊文件 / dev / random 和 的/ dev / urandom的 即可。

Entropy is the randomness collected/generated by an operating system or application for use in cryptography or other uses that require random data. This randomness is often collected from hardware sources, either from the hardware noises, audio data, mouse movements or specially provided randomness generators. The kernel gathers the entropy and stores it is an entropy pool and makes the random character data available to the operating system processes or applications through the special files /dev/random and /dev/urandom.

从 / dev / random 读取带有请求的位/字节数的熵池,提供高密码操作中经常需要的随机程度。如果熵池完全耗尽并且没有足够的熵,则 / dev / random 上的读取操作将阻塞,直到收集到额外的熵。因此,从 / dev / random 读取的应用程序可能会阻塞一段随机时间。

Reading from /dev/random drains the entropy pool with requested amount of bits/bytes, providing a high degree of randomness often desired in cryptographic operations. In case, if the entropy pool is completely drained and sufficient entropy is not available, the read operation on /dev/random blocks until additional entropy is gathered. Due to this, applications reading from /dev/random may block for some random period of time.

与上述情况相反,从 / dev / urandom 读取不会阻止。从 / dev / urandom 中读取也会消耗熵池,但是当缺少足够的熵时,它不会阻塞,而是重用部分读取的随机数据中的位。据说这容易受到密码分析攻击。这是一种理论上的可能性,因此不鼓励从 / dev / urandom 读取以在加密操作中收集随机性。

In contrast to the above, reading from the /dev/urandom does not block. Reading from /dev/urandom, too, drains the entropy pool but when short of sufficient entropy, it does not block but reuses the bits from the partially read random data. This is said to be susceptible to cryptanalytical attacks. This is a theorotical possibility and hence it is discouraged to read from /dev/urandom to gather randomness in cryptographic operations.

默认情况下,java.security.SecureRandom 类从 / dev / random 文件读取,因此有时会阻塞随机时间段。现在,如果读取操作没有返回所需的时间,则Oracle服务器会超时客户端(在本例中为jdbc驱动程序)并通过从其末端关闭套接字来断开通信。从阻塞调用返回后尝试恢复通信的客户端遇到IO异常。这个问题可能在任何平台上随机出现,尤其是从硬件噪声中收集熵。

The java.security.SecureRandom class, by default, reads from the /dev/random file and hence sometimes blocks for random period of time. Now, if the read operation does not return for a required amount of time, the Oracle server times out the client (the jdbc drivers, in this case) and drops the communication by closing the socket from its end. The client when tries to resume the communication after returning from the blocking call encounters the IO exception. This problem may occur randomly on any platform, especially, where the entropy is gathered from hardware noises.

正如OTN论坛所建议的,这个问题的解决方案是覆盖 java.security.SecureRandom 类的默认行为,使用来自 / dev / urandom 的非阻塞读取,而不是来自 / dev / random 的。这可以通过将以下系统属性 -Djava.security.egd = file:/// dev / urandom 添加到JVM来完成。虽然这对于像JDBC驱动程序这样的应用程序来说是一个很好的解决方案,但对于执行密码密钥生成等核心加密操作的应用程序来说,这是不鼓励的。

As suggested in the OTN forum, the solution to this problem is to override the default behaviour of java.security.SecureRandom class to use the non-blocking read from /dev/urandom instead of the blocking read from /dev/random. This can be done by adding the following system property -Djava.security.egd=file:///dev/urandom to the JVM. Though this is a good solution for the applications like the JDBC drivers, it is discouraged for applications that perform core cryptographic operations like crytographic key generation.

其他解决方案可能是使用可用于平台的不同随机播种器实现,不依赖于硬件噪声来收集熵。有了这个,您可能仍需要覆盖 java.security.SecureRandom 的默认行为。

Other solutions could be to use different random seeder implementations available for the platform that do not rely on hardware noises for gathering entropy. With this, you may still require to override the default behaviour of java.security.SecureRandom.

在Oracle服务器端增加套接字超时也可以是一种解决方案,但在尝试此操作之前,应从服务器的角度评估副作用。

Increasing the socket timeout on the Oracle server side can also be a solution but the side effects should be assessed from the server point of view before attempting this.

更多推荐

Oracle JDBC间歇性连接问题

本文发布于:2023-11-16 15:58:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605728.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:间歇性   Oracle   JDBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!