org.apache.commons.dbcp.DelegatingCallableStatement无法强制转换为oracle.jdbc.OracleCallableStatement

时间:2015-10-20 16:58:01

标签: java jdbc oracle11g apache-commons-dbcp

我正在使用Apache Commons DBCP(commons-dbcp-1.2.2.jar)连接池并导入org.apache.commons.dbcp.DelegatingConnection。 由于一些性能问题,我升级到commons-dbcp2-2.1.1.jar并导入了org.apache.commons.dbcp2.DelegatingConnection。 但在执行以下异常时

java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement

知道为什么会这样。

Java代码

public static Connection getOracleConnection(java.sql.Connection con) throws SQLException
{
    Connection oracleCon = null;

    if(con instanceof com.p6spy.engine.spy.P6Connection)
    {
        oracleCon = (oracle.jdbc.OracleConnection)((P6Connection)con).getJDBC();

    }
    else if(con instanceof P6LogConnection)
    {
        oracleCon = (oracle.jdbc.OracleConnection)((P6LogConnection)con).getJDBC();
    }
    else if(con instanceof DelegatingConnection)
    {
        Object innerMostObj = ((DelegatingConnection)con).getInnermostDelegate();

        if(innerMostObj instanceof oracle.jdbc.OracleConnection )
        {
            oracleCon = (oracle.jdbc.OracleConnection)innerMostObj;

        }
        else if(innerMostObj instanceof P6LogConnection)
        {
            oracleCon = ((P6LogConnection)innerMostObj).getJDBC();

        }
        else if(innerMostObj instanceof P6Connection)
        {
            oracleCon = ((P6Connection)innerMostObj).getJDBC();
        }
    }        
    else
    {
        oracleCon = con;
    }

    return oracleCon;
}

栈跟踪

[ERROR] 2015-10-20 08:55:49 com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:933) - Exception occured in Personalizationjava.lang.Exception: com.jatin.ebook.common.exception.EBookException: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1132) - calling loadLoginPageResources: languageID[-1]
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3129) - getTagValueFromLanguageResourcesBasedOnPlatform :: languageID:-1, platform:null
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3139) - platform id is null
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3147) - getLanguageResources(category = ui_jsp, languageID = -1) is invoked...
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:621) - getTagValueFromLanguageResources (category: ui_jsp,languageID: -1,key: null, platformID0) is requested
[INFO ] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:494) - getLanguageResourcesXML (category:ui_jsp,languageID:-1,key:null,platformID:0) is requested
[ERROR] 2015-10-20 08:55:49 com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:643) - Exception occurred in getTagValueFromLanguageResources
java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
    at com.jatin.ebook.persistence.util.StoredProcUtil.registerAndSetProcParameters(StoredProcUtil.java:280)
    at com.jatin.ebook.persistence.util.StoredProcUtil.executeStoredProc(StoredProcUtil.java:82)
    at com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:556)
    at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:627)
    at com.jatin.ebook.services.controller.LanguageStringProcessorController.executeController(LanguageStringProcessorController.java:92)
    at com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:51)
    at com.jatin.ebook.common.delegate.EBookDelegate.executeEvent(EBookDelegate.java:17)
    at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3166)
    at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3140)
    at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1133)
    at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:935)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.jatin.ebook.presentation.filter.EBookAccessFilter.doFilter(EBookAccessFilter.java:686)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:745)
[ERROR] 2015-10-20 08:55:49     com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:66) - EBookException in executeEvent:
com.jatin.ebook.common.exception.EBookException: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
    at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:644)
    at com.jatin.ebook.services.controller.LanguageStringProcessorController.executeController(LanguageStringProcessorController.java:92)
    at com.jatin.ebook.services.EBookSession.executeEvent(EBookSession.java:51)
    at com.jatin.ebook.common.delegate.EBookDelegate.executeEvent(EBookDelegate.java:17)
    at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResources(EBookViewerServiceUtil.java:3166)
    at com.jatin.ebook.flashremoting.util.EBookViewerServiceUtil.getTagValueFromLanguageResourcesBasedOnPlatform(EBookViewerServiceUtil.java:3140)
    at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.loadLoginPageResources(LoginPersonalizationAction.java:1133)
    at com.jatin.ebook.presentation.actions.LoginPersonalizationAction.execute(LoginPersonalizationAction.java:935)
    at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
    at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForward(PerformForward.java:113)
    at org.apache.struts.chain.commands.servlet.PerformForward.perform(PerformForward.java:96)
    at org.apache.struts.chain.commands.AbstractPerformForward.execute(AbstractPerformForward.java:54)
    at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
    at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
    at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.jatin.ebook.presentation.filter.EBookAccessFilter.doFilter(EBookAccessFilter.java:686)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:615)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: org.apache.commons.dbcp.DelegatingCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
    at         com.jatin.ebook.persistence.util.StoredProcUtil.registerAndSetProcParameters(StoredProcUtil.java:280)
    at com.jatin.ebook.persistence.util.StoredProcUtil.executeStoredProc(StoredProcUtil.java:82)
    at com.jatin.ebook.services.appservices.LanguageStringService.getLanguageResourcesXML(LanguageStringService.java:556)
    at com.jatin.ebook.services.appservices.LanguageStringService.getTagValueFromLanguageResources(LanguageStringService.java:627)
    ... 53 more

0 个答案:

没有答案