java jdbc Protocol violation錯誤

e71hao發表於2016-11-16
Cause: java.sql.SQLException: Protocol violation: [48]
; uncategorized SQLException for SQL []; SQL state [99999]; error code [17401]; Protocol violation: [48]; nested exception is java.sql.SQLException: Protocol violation: [48]
網上查到的資料是這樣的,做個筆記:

SQLException: Protocol violation. Oracle JDBC Driver issue


java.sql.SQLException: Protocol violation caught while accessing a page and Oracle DB is used


開啟上面連結,看到意思是    

Symptom

This exception was happening occasionally. The stack trace had different sql in it which was very confusing. Running the sql with sql plus worked fine.

Root Cause

The exception was thrown when oracle driver was trying to export a CLOB data. This was happening with only few records, not all of them. The data as such was a file. Visually we could not make out what was wrong with that data.

Why we were seeing errors in oracle logs ?

So if this was a driver defect, why did we see the error in oracle trace ? Logically the driver errors should be only confined to application logs. The reasons was that when protocol violation happened, the connection got corrupted. This connection was returned to the connection pool. Any user or job when will use that connection would not work and would experience error. That is why it will happen at random places, with random users

Solution

A short term fix was to change this property in connection pool. We are using DBCP connection pool.

Changed from ds.setTestOnBorrow(false); to ds.setTestOnBorrow(true);

Now when the pool returns a corrupted connection to the pool, before app borrows this connection , it would test for validity. If connection is unusable, pool would discard and then app gets a new/valid connection.

If you enable connection pool logs, you should see the exception which normally is swallowed.

Driver Upgrade

Upgrade to OJDBC 12.1.0.2 from OJDBC 12.1.0.1 solved the problem, even for the problematic rows.

Some other links for reference

%3A+Protocol+violation+caught+while+accessing+a+page+and+Oracle+DB+is+used

總結:主要意思是和ojdbc驅動有關係,對應的jdk,對應的資料庫版本使用對應的ojdbc。 然後去官網下載對應的jdbc版本,連結地址是:
oracle jdbc驅動下載


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30393770/viewspace-2128582/,如需轉載,請註明出處,否則將追究法律責任。

相關文章