面对java.lang.classcastexception com.ibm.ws.rsadapter.jdbc.wsjdbcconnection与Websphere 8.5中的oracle.jdbc.oracleConnection不兼容。该应用程序可以在weblogic中正常运行
使用JNDI在Websphere8.5上运行我的代码时遇到此异常。但是,相同的代码在Weblogic 8.1,Tomcat 5.5,JBoss 4.2.x上运行良好。 该代码还可以通过 JNDI 使用数据源(WebSphere Application Server V4)
正常运行当我通过非JNDI运行应用程序时,代码也可以正常工作。但是,当我通过JNDI在Websphere中使用 DataSource配置时,下面提到的异常即将到来。
下面是即将来临的异常的堆栈跟踪
com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection
*java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection*
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:149)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:115)
at com.syfact.mo.administrator.pctr.LoadAction.loadPostalcodes(LoadAction.java:182)
at com.syfact.mo.administrator.pctr.LoadAction.doAction(LoadAction.java:490)
at com.syfact.web.servlet.Syfact.processStandardCommand(Syfact.java:370)
at com.syfact.web.servlet.Syfact.doPost(Syfact.java:291)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:966)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:907)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:145)
at com.syfact.ConnectionFilter.doFilter(ConnectionFilter.java:40)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:190)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:130)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:87)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:696)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:641)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475)
at com.ibm.ws.wswebcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:463)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3107)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:238)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:811)
at com.ibm.ws.wswebcontainer.WebContainer.handleRequest(WebContainer.java:1425)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:92)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:465)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:394)
at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:102)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:152)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:213)
at com.ibm.io.async.AbstractAsyncFuture.fireCompletionActions(AbstractAsyncFuture.java:195)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:136)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:193)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:725)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:847)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1498)
我一直在寻找有关此问题的解决方案已有近一周的时间,
示例:
connection = (Connection) WSJdbcUtil.getNativeConnection((WSJdbcConnection)dataSource.getConnection());
OracleCallableStatement ocstmt = (OracleCallableStatement) connection.prepareCall(sql); "*
我不想在我的项目中拥有WAS库,因为我的代码不仅要部署在Websphere上,而且应该可以部署在Tomcat,JBoss,Weblogic .etc .......
答案 0 :(得分:3)
为了访问特定于JDBC驱动程序供应商的接口,您需要使用为此目的而存在的JDBC规范定义的展开API,
OracleConnection oraCon = connection.unwrap(oracle.jdbc.OracleConection.class);