title: ClassCastException DataSource cannot be cast to javax.sql.ConnectionPoolDataSource
body: <p>I'm getting this exception:</p>
  
  <pre><code>java.lang.ClassCastException: org.apache.tomcat.jdbc.pool.DataSource cannot be cast to javax.sql.ConnectionPoolDataSource
  </code></pre>
  
  <p>When I try to run my webapp (in Tomcat6) that use tomcat jdbc pool that seamlessly work with Tomcat7</p>
  
  <p>I have included these jars already in tomcat 6 lib folder:</p>
  
  <pre><code>tomcat-jdbc.jar
  tomcat-juli.jar
  </code></pre>
  
  <p>What could be the problem?</p>
  
  <p><strong>Update:</strong></p>
  
  <pre><code>protected static Connection getConnection() throws NamingException, SQLException {
      InitialContext cxt = new InitialContext();
      String jndiName = "java:/comp/env/jdbc/MyDBHrd";
      ConnectionPoolDataSource dataSource = (ConnectionPoolDataSource) cxt.lookup(jndiName); // ClassCastException here....
      PooledConnection pooledConnection = dataSource.getPooledConnection();
      Connection conn = pooledConnection.getConnection();
      return conn; // Obtain connection from pool
  } 
  </code></pre>
  
  <p><strong>Configuration:</strong></p>
  
  <pre><code>&lt;Resource name="jdbc/MyDBHrd"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            testWhileIdle="true"
            testOnBorrow="true"
            testOnReturn="false"
            validationQuery="SELECT 1"
            validationInterval="30000"
            timeBetweenEvictionRunsMillis="30000"
            maxActive="5000"
            minIdle="10"
            maxWait="10000"
            initialSize="20"
            removeAbandonedTimeout="120"
            removeAbandoned="true"
            logAbandoned="false"
            minEvictableIdleTimeMillis="30000"
            jmxEnabled="true"
            jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
              org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
            username="sa"
            password="password"
            driverClassName="net.sourceforge.jtds.jdbc.Driver"
            url="jdbc:jtds:sqlserver://192.168.114.130/MyDB"/&gt;
  </code></pre>
  
  <p>When I change the "type":</p>
  
  <pre><code> type="javax.sql.ConnectionPoolDataSource"
  </code></pre>
  
  <p>I get this warning:</p>
  
  <pre><code>WARNING: javax.sql.ConnectionPoolDataSource is not a valid class name/type for this JNDI factory.
  </code></pre>
  
  <p>Causing the <code>getConnection()</code> to return NULL.</p>
  
  <p><strong>Imports:</strong></p>
  
  <pre><code>import java.io.IOException;
  import java.sql.CallableStatement;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Timestamp;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Date;
  import java.util.Map;
  
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.sql.ConnectionPoolDataSource;
  import javax.sql.PooledConnection;
  
  import org.apache.commons.dbutils.DbUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  </code></pre>