title: Why do I need to call Class.forName in Tomcat Web Application even if I use a JDBC Driver 4.0?
body: <p>I'm studing Java Web, and during my studies I learned that from version 4 of the JDBC no need to use the method <code>Class.forName</code> to load the driver. I confirmed this information in this <a href="http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html" rel="nofollow">link</a>.</p>
  
  <p>Based on this information, I developed my getConnection method without that call, but when I started my Tomcat and I went to test my method, the following exception was thrown.</p>
  
  <pre><code>jan 23, 2015 7:55:48 PM org.apache.catalina.core.StandardWrapperValve invoke
  GRAVE: Servlet.service() for servlet [br.com.caelum.servlet.AdicionaContatoServlet] in context with path [/fj21-agenda] threw exception
  java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
      at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:14)
      at br.com.caelum.jdbc.dao.ContatoDAO.&lt;init&gt;(ContatoDAO.java:19)
      at br.com.caelum.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:51)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
      at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Unknown Source)
  Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)
      ... 25 more
  </code></pre>
  
  <p>I'm using on my tests:</p>
  
  <ul>
  <li>Tomcat 8</li>
  <li>Java 8</li>
  <li>Eclipse Luna Service Release 1 (4.4.1)</li>
  <li>mysql-connector-java-5.1.34-bin.jar</li>
  </ul>
  
  <p>If I include the line <code>Class.forName("com.mysql.jdbc.Driver");</code> all works fine. Someone have any idea about this?</p>