简体   繁体   中英

SQLException: Protocol Violation in oracle

I am getting the "Protocol Violation". I have an application running on RedHat Linux.The database and the application are co-resident on the machine.

Oracle version used: Oracle 11g R2 (11.2.0.3.0)
JDBC Driver used: 12.1.0.1
Java used: jdk1.7.0.65 32-bit

I have come across many forums where this error has been pointed out to be a driver issue but in all those forums the oracle version used was higher and the driver version were older and changing the driver resolved the issue.But in my case the Oracle version is lower but driver version is higher.So , in this case will the higher version of the the driver could be a problem?

Also, this protocol violation can also arise when the maximum number of connections on the DB is reached ?

Error Message:

java.sql.SQLException: Protocol violation: [72] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:464) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884) at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)

I had this exact error appearing randomly.

The application was running out of memory and the OutOfMemory error was lost due to the logic in the code which resulted in an unrelated exception being thrown.

One of the reasons applications shouldn't handle throwables and errors.

Such an error indicates a bug in the JDBC thin driver which is not able to understand what the server is returning on the wire (socket).

You can always try to use the very latest JDBC thin driver hoping that the bug will be resolved. As of today the latest is 12.1.0.2.

If that doesn't help then you will need to reach out to Oracle support. The first thing you will be asked is to provide the sqlnet trace of the connection where this error happened. This will help the Oracle engineers understand what was happening on the network when the failure happened.

To turn on sqlnet tracing, edit your sqlnet.ora file on the server and add

TRACE_LEVEL_SERVER = 16

which will add a trace file for each connection in your trace director (on the server). Don't do this on a production system because it will slow down the system dramatically and will generate huge amount of traces.

Good luck.

In my case, using getGeneratedKeys() of PreparedStatement to get current sequence value caused the protocol violation exceptions. Replacing it with obtain sequence current value from sequence, as follows:

String curSeqValQuery = "SELECT seq_name.CURRVAL FROM DUAL";
...
statement = con.prepareStatement(curSeqValQuery);
resultSet = (OracleResultSet) statement.executeQuery();
...

resolved the issue.

ojdbc7.jar 中已修复的问题 - 版本 12.1.0.2(版本可以在 jar 的 META-INF 文件中检查)

This usually indicates corrupted tcp/ip traffic. This can be due to injected traffic, or dropped packets. Do a ifconfig to see if any of your network interfaces is being affected by an unusual high amount of dropped packets. To avoid issues, as you indicate that database and java program are running on the same machine, try to use the loopback interface 127.0.0.1 (localhost), rather than it's external IP to connect to the database, or the other way around just for a test.

Not researched this further, but I guess it could also happen when driver and database version are too far apart. Getting driver to match installed oracle should not be too difficult.

It could simply be that the connection is infected or invalid. If your JDBC connection comes from a Connection Pool, always make sure you test the connection upon reserve.

In my case this happened when we were trying to extract the data using ojdbc driver targeting db link from another datasource, we were not connecting to the direct datasource. Once we connected through direct connection instead of using db link the issue stopped to appear.
Another thing I noticed is that the issue was happening in a consistent manner when we were trying to extract data from a column that has Chinese/Japanese characters.
Finally, extracting the data in chunks acted as an appropriate solution too.
HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM