将OraclePreparedStatement与DBCP连接一起使用 [英] Using OraclePreparedStatement with DBCP Connection

查看:199
本文介绍了将OraclePreparedStatement与DBCP连接一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用dbcp框架为我的oracle服务器建立连接池. 我使用了教程进行连接. 问题是使用以下连接创建OraclePreparedStatement:

I'm trying to make a connection pool with the dbcp framework for my oracle server. I used this tutorial for the connection. The problem is to create a OraclePreparedStatement with this connection:

Connection oracleCon;
OraclePreparedStatement o_stmt;
String sql = "INSERT INTO T002_metadata (T002_datacitexml,T002_version, T002_active)       VALUES (?,?,?) RETURNING T002_id INTO ?";


oracleCon = ConnectionManager.ds.getConnection();

o_stmt = ((OraclePreparedStatement) oracleCon.prepareStatement(sql));

执行此操作后,将引发异常.

After executing this, an exception is thrown.

org.apache.commons.dbcp.DelegatingPreparedStatement cannot be cast to oracle.jdbc.OraclePreparedStatement

是否有可能进行声明?

推荐答案

不是Oracle类,不是.这就是JDBC的目的.这是一个API.仅使用java.sql.PreparedStatement.通过尝试向下转换,您违反了多态性并破坏了诸如此类的事情,其中​​一个库包装了实际的连接和语句,以为您提供一些其他服务.

Not to an Oracle class, no. That's what JDBC is for. It's an API. Use java.sql.PreparedStatement only. By attempting to downcast, you violate polymorphism and break things like this, where a library is wrapping the real connection and statement to provide some additional services for you.

这篇关于将OraclePreparedStatement与DBCP连接一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆