How to create oracle connection in Spring application deployed in JBoss Server? (WrappedConnectionJDK6 cannot be cast to oracle.jdbc.OracleConnection)

笑着哭i 提交于 2021-02-08 09:51:14

问题


I want to create oracle connection. Currently i am passing jdbc connection to create struct descriptor and here i am getting exception as below. so to avoid this, required to create a java.sql.connection or oracle connection instead of getting from data source.

org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6 cannot be cast to 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)

Below is the piece of code where the above exception is coming.

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;");    

Help in this regared would be highly appreciated.


回答1:


Error is caused because you are trying to pass JBOSS's WrappedConnection into Oracle's utility class.

According to this https://community.jboss.org/wiki/SetUpAOracleDatasource you need to do the following:

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);
//...


来源:https://stackoverflow.com/questions/15086875/how-to-create-oracle-connection-in-spring-application-deployed-in-jboss-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!