WSJDBCConnection does not wrap objects of type Oracle jdbc Connection

后端 未结 3 1539
刺人心
刺人心 2020-12-11 11:32

I am using Websphere liberty server to run my application and I need to use ArrayDescriptor for passing arrays to the oracle stored procedure. I get an exceptio

相关标签:
3条回答
  • 2020-12-11 11:53

    If someone has this problem here is my solution.

    My mistake was that I was deploying my application to the dropins folder and if you define an application/webApplication in your server.xml it is ignored. I deployed it somewhere else, set this new location to the application tag and also added the <classloader> in server.xml, left the ojdbc jar as provided in pom.xml and it works now.

    But still I had a problem when I was running the application locally, because the ojdbc jar was provided in pom.xml.
    My solution was to use reflection to get the system class loader and load the jar at runtime for the local profile.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-11 12:03

    I just tested this on WebSphere Liberty and the following code worked for me:

    @Resource(lookup = "jdbc/oracle")
    private DataSource ds;
    
    // ...
    
    Connection conn = ds.getConnection();
    OracleConnection oracleConn = conn.unwrap(oracle.jdbc.OracleConnection.class);
    

    My server.xml looks like this:

    <dataSource jndiName="jdbc/oracle">
        <jdbcDriver libraryRef="oracleLib"/>
        <properties.oracle URL="${jdbc.URL}" user="${jdbc.user}" password="${jdbc.password}"/>
    </dataSource>
    
    <library id="oracleLib">
        <fileset dir="${server.config.dir}/oracle"/>
    </library>
    
    <application location="myApp.war" >
        <classloader commonLibraryRef="oracleLib"/>
    </application>
    

    The important thing to note here is the use of commonLibraryRef on the <classloader> element. If you use privateLibraryRef it will not work because the app and server-defined datasource will use isolated classloaders to load the Oracle JDBC classes.

    If this answer isn't helpful to you, please update your question with your server.xml configuration, and also how you are obtaining an instance of your DataSource.

    0 讨论(0)
  • 2020-12-11 12:12

    I tried the same thing in my local machine, but not worked because of same ojdbc jar available in the liberty run time server path. After removing its works fine. LibertyRuntime(In project explorer)-> servers(choose the deployed server)-> apps->you could see application-name.war.xml(Please remove the ojdbc jar from the xml).

    Make sure the jar is not available in the xml file Finally start the server, It will work.

    0 讨论(0)
提交回复
热议问题