Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Error in setting up a datasource in Tomcat 6.0's JNDI

Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a struts newbie and was trying to access a MySQL 5.1 database from the struts application for a login registration tutorial. After reading a tutorial from Tomcat 6.0 documentation for setting up a datasource in JNDI, I created a test table in the DB and tried to access it from a jsp according to the tutorial. It works fine but when I try to access it from an action, I get an exception message like this

org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class java.lang.ClassCastException
Mar 20, 2008 2:48:49 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
at com.yourcompany.struts.action.TestAction.execute(
at org.apache.struts.action.RequestProcessor.processActionPerform(
at org.apache.struts.action.RequestProcessor.process(
at org.apache.struts.action.ActionServlet.process(
at org.apache.struts.action.ActionServlet.doGet(
at javax.servlet.http.HttpServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
at Source)
This is the code which I used in the action. According to the MVC, DAO should be done from a model is what I infer. But I just wanted to try it from an action for test purposes

Please help me with this!
Thanks in advance

[ March 20, 2008: Message edited by: Vidya Moorthy ]

[ March 20, 2008: Message edited by: Vidya Moorthy ]
[ March 20, 2008: Message edited by: Vidya Moorthy ]
Posts: 9615
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need this explicit cast because getConnection is declared to return Connection implementation:

I'm at a loss as to why that cast would throw a ClassCastException, however.
Vidya Moorthy
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was it. I changed the line to
java.sql.Connection conn = ds.getConnection();
based on your suggestion and it worked. Wow, I have been stuck at this for almost 2 days now. Thanks a ton!
Villains always have antidotes. They're funny that way. Here's an antidote disguised as a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic