title: SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user '<<USERNAME>>'@'SERVERIP' (using password: YES))
body: <p>I'm having an OpenShift site which is trying to connect to an external MySQL server. Below is the code I have so far.</p>
  
  <pre><code>public class BaseDAO {
  static final String DB_DRIVER = "com.mysql.jdbc.Driver";
  DataSource datasource;
  
  
  public BaseDAO() {
      System.out.println("+++++ " +Calendar.getInstance().getTime());
      try{
          InitialContext ic = new InitialContext();
          Context initialContext = (Context) ic.lookup("java:comp/env");
          datasource = (DataSource) initialContext.lookup("jdbc/MySQLDS");
          Class.forName(DB_DRIVER).newInstance();
      } catch(Exception e){
          e.printStackTrace();
          throw new RuntimeException(e.getCause());
      }
    }
  }
  </code></pre>
  
  <p>All my DAO classes extend the BaseDAO so I won't have to type all of this 5-6 times. </p>
  
  <p>After some configuration, this does work on a local MySQL server. I have created a small application that either sends me to the index.jsp when the array gathered from the database is not null or not empty, and sends me to the about.jsp if it either is empty or null.</p>
  
  <p>Now in both the local and the external database I have create a table with the same name, column 'day' and inserted 1 value. When I run this locally it sends me to the index page, but when I run this via my OpenShift webpage it sends me to the about page.</p>
  
  <p>This is the error found in the SSH/app-root/logs/jbossews.log (username and serverip commented out)
  :</p>
  
  <p><strong>NOTE: THE SERVERIP AND LOGINCREDENTIALS ARE PROVIDED BY THE DATASOURCE OF OPENSHIFT</strong></p>
  
  <p>The path to the DAO is: OpeningsTijdenServlet --> (static)ServiceProvider --> OTService --> OpeningsTijdenDAO (extends BaseDAO)</p>
  
  <pre><code>INFO: Server startup in 10894 ms
  +++++ Mon Oct 12 16:07:51 EDT 2015
  org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create      PoolableConnectionFactory (Access denied for user '&lt;&lt;USERNAME&gt;&gt;'@'SERVERIP' (using password: YES))
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1551)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1390)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1046)
      at main.java.database.OpeningsTijdenDAO.selectTijden(OpeningsTijdenDAO.java:16)
      at main.java.database.OTService.getTijden(OTService.java:13)
      at main.java.servlets.GetTijdenServlet.doPost(GetTijdenServlet.java:17)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1042)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.sql.SQLException: Access denied for user '&lt;&lt;USERNAME&gt;&gt;'@'SERVERNAME' (using password: YES)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
      at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
  </code></pre>