title: how to solve this java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.jdbc.pool.DataSource?
body: <p>I am trying to do the database connection in tomcat using pooling, this is the what is my context : </p>
  
  <pre><code>&lt;Resource name="jdbc/slingemp" auth="Container" type="javax.sql.DataSource"
                 maxActive="100" maxIdle="30" maxWait="10000"
                 username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
                 url="jdbc:mysql://localhost:3306/slingemp"/&gt;
  </code></pre>
  
  <p>and this is what is my web.xml : </p>
  
  <pre><code>&lt;description&gt;MySQL JNDI Test&lt;/description&gt;
    &lt;resource-ref&gt;
      &lt;description&gt;DB Connection&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/slingemp&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;
  </code></pre>
  
  <p>and this is how i connect with database : </p>
  
  <pre><code> package org.slingemp.jnditest;
  
  import java.io.IOException;
  import java.sql.Connection;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.tomcat.jdbc.pool.DataSource;
  
  /**
   * Servlet implementation class JNDILookUpServlet
   */
  @WebServlet("/JNDILookUpServlet")
  public class JNDILookUpServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public JNDILookUpServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          try {
              Context initContext = new InitialContext();
              Context envContext  = (Context)initContext.lookup("java:/comp/env");
              DataSource ds = (DataSource)envContext.lookup("jdbc/slingemp");
              Connection conn = ds.getConnection();
              if(conn != null)System.out.println("Connected..");
              else System.out.println("Not connected...");
          } catch (Exception e) {
              e.printStackTrace();
          }
          response.sendRedirect("index.jsp");
      }
  
  
  }
  </code></pre>
  
  <p>but it gives me the following exception : </p>
  
  <pre><code>java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp.BasicDataSource cannot be cast to org.apache.tomcat.jdbc.pool.DataSource
  </code></pre>
  
  <p>Please help me to resolve this,</p>
  
  <p>Regards</p>