Cannot create PoolableConnectionFactory (Could not create connection to database server )
<p>I'm trying to create a J2EE application for the first time. </p>

<p>I created my database on MySQL and now I want to get all data on my screen with my application. </p>

<p>The problem is : When I want to connect the application on the MySQL database, I have the error : </p>

<pre><code>java.sql.SQLException: Cannot create PoolableConnectionFactory (Could not create connection to database server. Attempted reconnect 3 times. Giving up.)
</code></pre>

<p>I'm using : </p>

<ul>
<li>VirtualBox VM 5.0</li>
<li>Windows 7 </li>
<li>EasyPHP with MySQL (5.7.11 x86)</li>
<li>JDBC : MySQL Connector 5.1.31</li>
<li>Eclipse </li>
</ul>

<p>server.xml ( in c:/serveur/tomcat/conf/ )</p>

<p>
    </p>

<pre><code>&lt;Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" /&gt;


          &lt;!-- JNDI de la base nouvellebd --&gt;
&lt;Resource name="base_test" 
    type="javax.sql.DataSource" 
    password="" 
    driverClassName="com.mysql.jdbc.Driver" 
    maxIdle="2" 
    maxWait="500" 
    username="root" 
    url="jdbc:mysql://127.0.0.1/nouvellebd?autoReconnect=true"  
    maxActive="500"
/&gt;
</code></pre>

<p></p>

<p>My "context" ( in conf/catalina/localhost/ProjetServlet.xml ) :</p>

<pre><code>&lt;Context path="/ProjetServlet" 
    reloadable="true" 
    docBase="c:\MonEspace\ProjetServlet" 
    workDir="c:\MonEspace\ProjetServlet\work" &gt;
    &lt;ResourceLink
        name="base_test"
        global="base_test"
        type="javax.sql.DataSource"/&gt;
&lt;/Context&gt;
</code></pre>

<ul>
<li>I can connect myself on the MySQL server with CMD, there is no problem. </li>
<li>The JDBC file is added in c:/server/lib</li>
</ul>

<p>My Code (AffichePersonne.java): </p>

<pre><code>package mesServlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

public class AffichePersonne extends HttpServlet {


    Connection BD;
    DataSource ds;

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException {
                try {
                BD=ds.getConnection();
                Statement s = BD.createStatement();
                ResultSet r = s.executeQuery("select * from personne");
                PrintWriter out=null;
                resp.setContentType("text/html");
                out = resp.getWriter();
                out.println("&lt;html&gt;");
                out.println("&lt;head&gt;&lt;title&gt; Test servlet &lt;/title&gt;&lt;/head&gt;");
                out.println("&lt;body&gt;");
                out.println("Contenu de la table personne &lt;BR&gt;");
                out.println("&lt;table&gt;");
                out.println("&lt;TR&gt;");
                out.println("&lt;TD&gt;Nom&lt;/TD&gt;");
                out.println("&lt;TD&gt;Prénom&lt;/TD&gt;");
                out.println("&lt;/TR&gt;");
                while (r.next()) {
                    out.println("&lt;TR&gt;");
                    out.println("&lt;TD&gt;");
                    out.println(r.getString("nom"));
                    out.println("&lt;/TD&gt;");
                    out.println("&lt;TD&gt;");
                    out.println(r.getString("prenom"));
                    out.println("&lt;/TD&gt;");
                    out.println("&lt;/TR&gt;");
                    }
                out.println("&lt;/table&gt;");
                out.println("&lt;/body&gt;");
                out.println("&lt;/html&gt;");
                r.close();
                s.close();
                BD.close();
                s = null;
                r = null;
            } catch (java.sql.SQLException ex) {
                System.out.println("Erreur d'exécution de la requête SQL \n"+ex);
            } 
        }

    public void init() throws ServletException  {
        try {
        System.out.println("Récupération du contexte");
        Context initCtx = new InitialContext();
        System.out.println("lookup de env");
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        System.out.println("lookup de base_test");
        ds=(DataSource) envCtx.lookup("base_test");
        //System.out.println("Datasource chargée");
        }
        catch(Exception er) {
            System.out.println("Erreur de chargement du contexte " + er);
        }   }

}
</code></pre>

<p>The "mapping" (web.xml) : </p>

<pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;

&lt;!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd"&gt;
&lt;web-app&gt;
    &lt;display-name&gt;Mes servlets&lt;/display-name&gt;
    &lt;description&gt;
      Premi�res servlets
    &lt;/description&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;ServletHello&lt;/servlet-name&gt; 
        &lt;servlet-class&gt;mesServlets.HelloServlet&lt;/servlet-class&gt; 
        &lt;description&gt;Servlet d'essai&lt;/description&gt; 
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt; 
        &lt;servlet-name&gt;ServletHello&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/hello&lt;/url-pattern&gt; 
    &lt;/servlet-mapping&gt;  

    &lt;servlet&gt;
    &lt;servlet-name&gt;ServletBD&lt;/servlet-name&gt; 
    &lt;servlet-class&gt;mesServlets.AffichePersonne&lt;/servlet-class&gt; 
    &lt;description&gt;Servlet d'essai de la connection BD&lt;/description&gt; 
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt; 
    &lt;servlet-name&gt;ServletBD&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/essaibd&lt;/url-pattern&gt; 
    &lt;/servlet-mapping&gt;

&lt;/web-app&gt;
</code></pre>

<p>Thank you a lot for any help :) </p>