com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle.jdbc.OracleConnection 异常解决办法

原创
2018/12/05 14:29
阅读数 8.2K

在spring使用自带的dataSource配置:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

是没问题的,使用druid连接池

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">

就有问题。报如下错误:

java.lang.ClassCastException: com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle.jdbc.OracleConnection
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:105)
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:73)

异常代码:

Connection connection = ...;// Oracle

StructDescriptor st = new StructDescriptor("T_ORDER", connection);

// OR.

ARRAY deptArrayObject = new ARRAY(arrayDept, connection, list.toArray());

 

失败原因:

The connection pool usually has a wrapper around the real connection instance, that's why your cast fails.

连接池通常包装了一个真实的真实的Connection实例。

需要转换一下。

解决方案:

Connection connection = ...; // Oracle

// 增加此代码,将Connection转换为OracleConnection
connection = connection.unwrap(OracleConnection.class);

StructDescriptor st = new StructDescriptor("T_ORDER", connection);

 

参考链接:

Connection cannot be cast to oracle.jdbc.OracleConnection 

c3p0连接oracle的问题

展开阅读全文
打赏
1
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
1
分享
返回顶部
顶部