PoolingDataSource - 如何使用特定于驱动程序的PreparedStatement实现
我已经实现了 commons dbcp PoolingDataSource
及其工作完美 - 正常直到我遇到使用 java.sql.PreparedStatement 接口的特定实现的问题。
((OraclePreparedStatement) getStatement()).registerReturnParameter(index, sqlType);
java.lang.ClassCastException:
org.apache.commons.dbcp.DelegatingPreparedStatement
cannot be cast to oracle.jdbc.OraclePreparedStatemen
我明白为什么会发生这种情况。 有没有办法使用供应商特定的PreparedStatement实现,但仍然能够使用Commons DBCP提供的连接池?我想使用registerReturnParameter()和getReturnResultSet()这是特定于 Oracle 的实现的。我知道我违反了基本规则 #1 ...
此外,PoolingDataSource 正在包装 OracleXADataSource,这让我相信以某种方式可以做到这一点...
I've implemented the commons dbcp PoolingDataSource
and its working perfectly - right up until I ran into an issue of using a specific implementation of the java.sql.PreparedStatement
interface.
((OraclePreparedStatement) getStatement()).registerReturnParameter(index, sqlType);
java.lang.ClassCastException:
org.apache.commons.dbcp.DelegatingPreparedStatement
cannot be cast to oracle.jdbc.OraclePreparedStatemen
I understand why this is happening. Is there any way to use a vendor-specific implementation of PreparedStatement but still be able to use the connection pooling that is provided by Commons DBCP? I'd like to use the registerReturnParameter() and getReturnResultSet() which are specific to Oracle's implementation. I know I've violated cardinal rule #1 ...
Also, the PoolingDataSource is wrapping a OracleXADataSource which makes me believe that it's somehow possible to do this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DelegatingPreparedStatement
的名称意味着它只是委托给原始语句。因此,您调用deecatingPrepartedStatement.getDelegate()
,它将返回OraclePreparedStatement
。但实际上,尽量不要这样做。
The name of
DelegatingPreparedStatement
implies that it simply delegates to the original statement. So you calldelecatingPrepartedStatement.getDelegate()
which will return theOraclePreparedStatement
.But really, try not to do this.