title: IntelliJ java.lang.ClassNotFoundException: com.mysql.jdbc.Driver - connecting to XAMPP MySQL database
body: <p>Trying to create a basic login page in Java using IntelliJ. I've added the JAR to the CLASSPATH using these instructions: <a href="https://stackoverflow.com/questions/16742085/adding-jar-files-to-intellijidea-classpath">Adding Jar files to IntellijIdea classpath</a>. The error I'm getting is below. </p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
  at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:264)
  at main.Validate.checkUser(Validate.java:17)
  at main.Login.doPost(Login.java:23)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
  at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
  at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
  at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
  at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
  at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:745)
  20-Mar-2017 16:14:19.453 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory D:\Users\MYNAME\apache-tomcat-8.5.12\webapps\manager
  20-Mar-2017 16:14:19.523 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory D:\Users\MYNAME\apache-tomcat-8.5.12\webapps\manager has finished in 70 ms
  </code></pre>
  
  <p>The class that connects to the DB is called Validate;</p>
  
  <pre><code>package main;
  
  import java.sql.*;
  
  public class Validate
  {
      public static boolean checkUser(String username,String password)
      {
  
          boolean st =false;
          try{
  
              //loading drivers for mysql
              Class.forName("com.mysql.jdbc.Driver");
  
              //creating connection with the database
              Connection con=DriverManager.getConnection
                      ("jdbc:mysql:/ /localhost:3306/wpdcourseworkdb","root","");
              PreparedStatement ps =con.prepareStatement
                      ("select * from users where username=? and password=?");
              ps.setString(1, username);
              ps.setString(2, password);
              ResultSet rs =ps.executeQuery();
              st = rs.next();
  
          }catch(Exception e)
          {
              e.printStackTrace();
          }
          return st;
      }
  }
  </code></pre>