如何在JBoss Server中部署的Spring应用程序中创建oracle连接? (WrappedConnectionJDK6无法强制转换为oracle.jdbc.OracleConnection)

时间:2013-02-26 10:36:52

标签: java spring jdbc jboss jdbctemplate

我想创建oracle连接。目前我正在传递jdbc连接以创建结构描述符,在这里我得到例外,如下所示。所以要避免这种情况,需要创建一个java.sql.connection或oracle连接,而不是从数据源获取。

org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6无法强制转换为oracle.jdbc.OracleConnection

java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection
        at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:160)
        at oracle.sql.StructDescriptor.createDescriptor(StructDescriptor.java:131)

以下是上述例外的代码。

Connection conn = getDataSource().getConnection();
StructDescriptor itemDescriptor = StructDescriptor.createDescriptor(("EMP_DATA", conn);
StructDescriptor addressDescriptor = StructDescriptor.createDescriptor("EMP_ADDRESS", conn);
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("EMP_TABLE", conn);

/** Creating Objects */
Object[] itemAtributes = new Object[] {
        "XXX", "XXX", new STRUCT(addressDescriptor, conn, new Object[] {
                "XXX", "XXX", "XXX" }) };

STRUCT itemObject1 = new STRUCT(itemDescriptor, conn, itemAtributes);

itemAtributes = new Object[] {
        "YYY", "YYY", new STRUCT(addressDescriptor, conn, new Object[] {
                "YYY", "YYY", "YYY" }) };

STRUCT itemObject2 = new STRUCT(itemDescriptor, conn, itemAtributes);

STRUCT[] idsArray = {
        itemObject1, itemObject2 };

ARRAY array_to_pass = new ARRAY(descriptor, conn, idsArray);

/** Calling Procedure */
ps = (OraclePreparedStatement) conn.prepareStatement("begin Pr_save_emp(:x); end;");    

非常感谢您对此表示的帮助。

1 个答案:

答案 0 :(得分:1)

错误是由于您尝试将JBOSS的WrappedConnection传递到Oracle的实用程序类中而引起的。

根据此https://community.jboss.org/wiki/SetUpAOracleDatasource,您需要执行以下操作:

Connection dsConn = getDataSource().getConnection(); //JBoss wrapped connection
Connection conn = ((WrappedConnection)dsConn).getUnderlyingConnection(); //Oracle connection
//everything else remains the same
StructDescriptor itemDescriptor = StructDescriptor.createDescriptor(("EMP_DATA", conn);
//...