tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <dmik...@vmware.com>
Subject Re: Exception Message:org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.dbcp.dbcp.BasicDataSource
Date Mon, 09 Jul 2012 14:12:18 GMT
----- Original Message -----
> Hi All,
> 
> I am getting class cast exception when casting DataSource to
> BasicDataSource.
> The same is executed when run on JDeveloper.
> 
> Environment : Tomcat 7.X
> DB : Oracle
> 
> Used : tomcat-dbcp.jar,ojdbc14.jar

Where do you have these deployed?  WEB-INF/lib? $CATALINA_BASE/lib? $CATALINA_HOME/lib?


> context.xml

What is the location of this context file?  conf/context.xml? META-INF/context.xml? 


> 
> <Resource name="jdbc/ShipConsoleDS" auth="Container"
>   type="javax.sql.DataSource"
>   driverClassName="oracle.jdbc.OracleDriver"
>   url="jdbc:oracle:thin:@sharp.appsahyd.com:1521:DEV01"
>   username="apps" password="apps" maxActive="-1" maxIdle="0"
>   maxWait="-1" initialSize="15"
>   accessToUnderlyingConnectionAllowed="true" />
> 
> Java Code to access Data Source :
> 
> InitialContext initContext = new InitialContext();
> Context envContext = (Context) initContext.lookup("java:/comp/env");
> DataSource dataSource = (DataSource)
> envContext.lookup("jdbc/ShipConsoleDS");
> BasicDataSource bds = (BasicDataSource)dataSource;
> 
> 
> Exception :
> 
> Exception Message:org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot
> be cast to org.apache.tomcat.dbcp.dbcp.BasicDataSource

I've seen similar exceptions before when the BasicDataSource class loaded by two different
class loaders.  For example, from the common class loader and from the webapp class loader.
 Check your class path to see if this might be occurring.  

Also, you might want to add the "-verbose:class" option to your JVM options.  This will print
the classes that are loaded and the location from where they are loaded.  This is helpful
if the class is unknowingly loaded twice.

Dan



> java.lang.ClassCastException:
> org.apache.tomcat.dbcp.dbcp.BasicDataSource
> cannot
>  be cast to org.apache.tomcat.dbcp.dbcp.BasicDataSource
>         at
> com.aasc.model.AascOracleDAOFactory.createConnection(AascOracleDAOFac
> tory.java:96)
>         at
>         com.aasc.model.AascDBAccess.getConnection(AascDBAccess.java:58)
>         at
>         com.aasc.model.AascDBAccess.getValues(AascDBAccess.java:84)
>         at
> org.apache.jsp.aascShipConsoleIndex_jsp._jspService(aascShipConsoleIn
> dex_jsp.java:296)
>         at
>         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>         at
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>         at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
> .java:432)
>         at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
> 90)
>         at
>         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
>         at
>         javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
> icationFilterChain.java:305)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
> ilterChain.java:210)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
> alve.java:225)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
> alve.java:169)
>         at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
> torBase.java:472)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
> ava:168)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
> ava:98)
>         at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
> 927)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
> ve.java:118)
>         at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
> a:407)
>         at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp
> 11Processor.java:999)
>         at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
> AbstractProtocol.java:565)
>         at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoin
> t.java:309)
>         at
>         java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
> Source
> )
>         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
>         Source)
>         at java.lang.Thread.run(Unknown Source)
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message