Druid of the pit

When a query database Clob is converted to an Oracle Clob type.

java.lang.ClassCastException: com.alibaba.druid.proxy.jdbc.ClobProxyImpl cannot be cast to oracle.sql.CLOB
Copy the code

Question why

ClobProxyImpl cannot be converted to Oracle Clob fields, which is also drunk.

Because the Druid as Clob fields increases the proxy class: com. Alibaba. Druid. Proxy. JDBC. ClobProxyImpl, then code and forced into Oracle Clob appear the problem.

The solution

The solution is to convert the ClobProxy object to Druid’s proxy class and then retrieve the native Oracle Clob field contents.

public class ClobUtil { public static CLOB parseOracleClob(Clob clob) { SerializableClob sclob = (SerializableClob) clob; Clob wrappedClob = sclob.getWrappedClob(); If (wrappedClob instanceof ClobProxy) {ClobProxy = (ClobProxy) wrappedClob; wrappedClob = clobProxy.getRawClob(); } return (CLOB) wrappedClob; }}Copy the code

Recommended reading

Dry goods: 2TB architect four-stage video tutorial

Interview: the most complete Java multithreaded interview questions and answers

Interview: the most comprehensive ali advanced Java interview questions in history

Interview: The most complete Spring interview questions in history

Tutorial: The most complete Spring Boot complete video tutorial

Books: 15 must-read books for advanced Java architects

Tools: Recommended an online creation flow chart, mind mapping software

Share Java dry goods, high concurrency programming, hot technology tutorials, microservices and distributed technology, architecture design, blockchain technology, artificial intelligence, big data, Java interview questions, and cutting-edge hot news.