SQLException: Protocol Violation in oracle

2019-04-26 17:43发布

问题:

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)

回答1:

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.



回答2:

Increase the heap space!

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.



回答3:

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.



回答4:

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.



回答5:

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.



回答6:

The Issue fixed in ojdbc7.jar - version 12.1.0.2 (version you can check in META-INF file of jar)