title: JDBC connection pool to MySQL on OpenShift
body: <p>First of all, I'm a computer science student, and I'm not very much into computer science world yet (i.e. I've little experience doing stuff on my own). So sorry for not having all the knowledge possible on it.</p>
  
  <p>Then, in one of my classes I learnt how to create web application with java (jsp, beans, etc.) plus all the client-side stuff (html, css, javascript, ect.).</p>
  
  <p>I work on NetBeans IDE.</p>
  
  <p>To connect to a MySQL database, I use connection pooling in this way:</p>
  
  <p>1) Add MySQL JDBC Driver jar</p>
  
  <p>2) A DBConnect.java java class with a method that returns a connection:</p>
  
  <pre><code>public static Connection getConnection() {
      /* JNDI query to locate the DataSource object */
      Context initContext;
      try {
          initContext = new InitialContext();
          Context envContext = (Context) initContext.lookup("java:/comp/env"); // JNDI standard naming root
          DataSource ds = (DataSource) envContext.lookup("jdbc/aName");
  
          /* Ask DataSource for a connection */
          Connection conn;
          try {
              conn = ds.getConnection();
              return conn;
          } catch (SQLException ex) {
              Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
              throw new RuntimeException("cannot open Connection", ex);
          }
      } catch (NamingException ex) {
          Logger.getLogger(DBConnect.class.getName()).log(Level.SEVERE, null, ex);
          throw new RuntimeException("cannot find DataSource reference", ex);
      }
  }
  </code></pre>
  
  <p>3) web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
  
  &lt;resource-ref&gt;
      &lt;description&gt;Resource reference to a DataSource for managing a connection pool.&lt;/description&gt;
      &lt;res-ref-name&gt;jdbc/aName&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;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>4) context.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context antiJARLocking="true" path="/myApp"&gt;
      &lt;Resource 
       auth="Container" 
       driverClassName="com.mysql.jdbc.Driver" 
       maxActive="100" 
       maxIdle="30" 
       maxWait="10000" 
       name="jdbc/aName" 
       username="username" 
       password="password" 
       type="javax.sql.DataSource" 
       url="jdbc:mysql://"whateverhost":"whateverport"/dbSchema?autoReconnect=true"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>Now, I created a small project and I wanted to publish it online for free. I ran into OpenShift and I managed to push all my files on it (even if the folders' schema is different).</p>
  
  <p>The problem is that the connection pooling doesn't work, and I don't have a clue on what to do.</p>
  
  <p>Running the application, these are the exceptions: </p>
  
  <pre><code>java.lang.RuntimeException: cannot open Connection
  ....
  
  org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
  ....
  
  java.sql.SQLException: No suitable driver
  ....
  </code></pre>
  
  <p>mysql-connector jar is in /WEB_INF/lib and pom.xml has:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
      &lt;version&gt;5.1.25&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Maybe the solution is quite simple but I don't know what to do.
  Thank you.</p>