java jdbc Protocol violation错误

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

http://stackoverflow.com/questions/4685021/sqlexception-protocol-violation-oracle-jdbc-driver-issue
java.sql.SQLException: Protocol violation caught while accessing a page and Oracle DB is used

https://confluence.atlassian.com/confkb/java-sql-sqlexception-protocol-violation-caught-while-accessing-a-page-and-oracle-db-is-used-781393258.html
打开上面链接,看到意思是    

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

https://confluence.atlassian.com/display/CONFKB/java.sql.SQLException%3A+Protocol+violation+caught+while+accessing+a+page+and+Oracle+DB+is+used

总结:主要意思是和ojdbc驱动有关系,对应的jdk,对应的数据库版本使用对应的ojdbc。 然后去官网下载对应的jdbc版本,链接地址是:
oracle jdbc驱动下载
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30393770/viewspace-2128582/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30393770/viewspace-2128582/

你可能感兴趣的:(java jdbc Protocol violation错误)