Connecting Mysql with IntelliJ ultimate 2016.2.3 using JSP
<p>Am new in JSP and the IntelliJ IDE am experiencing an error <code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver</code> when i try to login inside my Application. Am using IntelliJ as my IDE while developing a JSP project.  <strong>How can I connect Mysql to a JSP project?</strong></p>

<p>Below is <strong>LoginDao.java</strong> class </p>

<pre><code>package com.huza.schooldynamic;

/**
 * Created by HUZY_KAMZ on 9/8/2016.
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class LoginDao {
    public static boolean validate(String name, String pass) {
        boolean status = false;
        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rs = null;

        String url = "jdbc:mysql://localhost:3306";
        String dbName = "form";
        String driver = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "namungoona";
        try {
            Class.forName(driver).newInstance();
            conn = DriverManager
                    .getConnection(url + dbName, userName, password);

            pst = conn

                .prepareStatement("select * from login where user=? and password=?");
        pst.setString(1, name);
        pst.setString(2, pass);

        rs = pst.executeQuery();
        status = rs.next();

    } catch (Exception e) {
        System.out.println(e);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (pst != null) {
            try {
                pst.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    return status;
}
</code></pre>

<p>}</p>

<p>and this is my servlet class <strong>LoginServlet.java</strong></p>

<pre><code>package com.huza.schooldynamic;

/**
 * Created by HUZY_KAMZ on 9/8/2016.
 */
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet{

    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String n=request.getParameter("username");
        String p=request.getParameter("userpass");

        HttpSession session = request.getSession(false);
        if(session!=null)
            session.setAttribute("name", n);

        if(LoginDao.validate(n, p)){
            RequestDispatcher rd=request.getRequestDispatcher("welcome.jsp");
            rd.forward(request,response);
        }
        else{
            out.print("&lt;p style=\"color:red\"&gt;Sorry username or password error&lt;/p&gt;");
            RequestDispatcher rd=request.getRequestDispatcher("index.jsp");
            rd.include(request,response);
        }

        out.close();
    }
}
</code></pre>

<p>This is my <strong>index.jsp</strong> file </p>

<pre><code>&lt;%--
  Created by IntelliJ IDEA.
  User: HUZY_KAMZ
  Date: 9/8/2016
  Time: 5:31 PM
  To change this template use File | Settings | File Templates.
--%&gt;
&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;School Management System&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;

  &lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;center&gt;
  &lt;form action="loginServlet" method="post"&gt;
    &lt;fieldset style="width: 300px"&gt;
      &lt;legend&gt; Login here &lt;/legend&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td&gt;User ID&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="username" required="required" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;Password&lt;/td&gt;
          &lt;td&gt;&lt;input type="password" name="userpass" required="required" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td&gt;&lt;input type="submit" value="Login" /&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/fieldset&gt;
  &lt;/form&gt;

  &lt;/center&gt;


  &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This is my <strong>welcome.jsp</strong> file</p>

<pre><code>&lt;%--
  Created by IntelliJ IDEA.
  User: HUZY_KAMZ
  Date: 9/8/2016
  Time: 6:00 PM
  To change this template use File | Settings | File Templates.
--%&gt;
&lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Welcome &lt;%=session.getAttribute("name")%&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h3&gt;Login successful!!!&lt;/h3&gt;
&lt;h4&gt;
    Hello,
    &lt;%=session.getAttribute("name")%&gt;&lt;/h4&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>And finally this is my <strong>web.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1"&gt;

    &lt;servlet&gt;
        &lt;servlet-name&gt;login&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.huza.schooldynamic.LoginServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;

    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;login&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/loginServlet&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</code></pre>

<p>So currently i have tried to view Mysql in the IntelliJ IDE but it seems i don't know how to connect it to the project , when i run the app and i try ti login this error comes in the IDE <code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver</code>.</p>

<p>Below is the picture of the IDE </p>

<p><a href="https://i.stack.imgur.com/QcNMC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QcNMC.png" alt="So in that picture , i view the database and the table , but how can i connect it to the project"></a> </p>