Reputation: 61
Trying to create BLOB object using BLOB.createTemporary(connection, false, BLOB.DURATION_SESSION)
,But getting Class Cast Exception
java.lang.ClassCastException: org.apache.commons.dbcp.cpdsadapter.ConnectionImpl cannot be cast to oracle.jdbc.OracleConnection.
I tried following suggestions but still same error .Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
Some one please suggest me to resolve this issue.
Upvotes: 0
Views: 1496
Reputation: 159086
The Oracle BLOB.createTemporary()
method expects the Connection
parameter to be a oracle.jdbc.OracleConnection
object, but connections from Tomcat are managed by DBCP, so the connection
is wrapped in a DBCP class (org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
).
You either need to unwrap it to get the real Oracle connection object, or stop using the Oracle BLOB
.
Just use the JDBC methods: Blob blob = connection.createBlob()
Update
The JDBC Blob
is an interface. There are no implementing classes in the JDK, so you'll always get a DBMS specific implementation. If needed, you can cast to OracleBlob
, which is also an interface, that provides additional Oracle-specific methods.
Interesting javadoc for OracleBlob:
Generally any new code should avoid the direct use of the class
BLOB
. For variable declarations use the interfaceBlob
or this interface as required. Instead of the static methodsBLOB.createTemporary(java.sql.Connection, boolean, int)
andBLOB.empty_lob()
please useConnection.createBlob()
andBLOB.getEmptyBLOB()
respectively.
Upvotes: 1