title: java servlets No suitable driver found for jdbc:mysql://localhost/crud_db
body: <p>This is a simple .jsp signup form:-</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Register page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
        &lt;form name="registration" method="post" action="RegServlet"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;First name&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="fname"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Last Name&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="lname"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Gender&lt;/td&gt;
                  &lt;td&gt;&lt;input type="radio" name="gender" id="male" value="male"&gt;&lt;label for="male"&gt;Male&lt;/label&gt;
                  &lt;input type="radio" name="gender" id="female" value="female"&gt;&lt;label for="female"&gt;Female&lt;/label&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;E-mail&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="email"&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="password"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Age&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="age"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Address&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="address"&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;State&lt;/td&gt;
                          &lt;td&gt;&lt;select name="state"&gt;
                                  &lt;option value="chd"&gt;Chd&lt;/option&gt;
                                  &lt;option value="punjab"&gt;Punjab&lt;/option&gt;
                                  &lt;option value="haryana"&gt;Haryana&lt;/option&gt;
                      &lt;/select&gt;&lt;/td&gt;
              &lt;/tr&gt; 
              &lt;tr&gt;
                  &lt;td&gt;Skills&lt;/td&gt;
                  &lt;td&gt;&lt;input type="checkbox" name="skill" value="java"&gt;Java
                  &lt;input type="checkbox" name="skill" value="php"&gt;Php
                  &lt;input type="checkbox" name="skill" value="wordpress"&gt;Wordpress&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;button type="submit" value="submit"&gt;submit&lt;/button&gt;
  
          &lt;/table&gt;&lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my servlet file:</p>
  
  <pre><code>package org.servlet.java;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.SQLException;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  public class RegServlet extends HttpServlet {
  
      StringBuilder csvSkills = new StringBuilder();
  
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          try (PrintWriter out = response.getWriter()) {
              /* TODO output your page here. You may use following sample code. */
              out.println("&lt;!DOCTYPE html&gt;");
              out.println("&lt;html&gt;");
              out.println("&lt;head&gt;");
              out.println("&lt;title&gt;Servlet RegServlet&lt;/title&gt;");
              out.println("&lt;/head&gt;");
              out.println("&lt;body&gt;");
              out.println("&lt;h1&gt;Servlet RegServlet at " + request.getContextPath() + "&lt;/h1&gt;");
              out.println("&lt;/body&gt;");
              out.println("&lt;/html&gt;");
          }
      }
  
      // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException 
  
      {
          processRequest(request, response);
          PrintWriter out = response.getWriter();
             out.println("---------servelt post method-----------------");
  
          String fname = request.getParameter("fname");
          String lname = request.getParameter("lname");
          String gender = request.getParameter("gender");
          String email = request.getParameter("email");
          String password = request.getParameter("password");
          String skill[] = {"dfdsf","sdfsdfds","dsff"};//request.getParameterValues("skill");
          String state = request.getParameter("state");
          String age = request.getParameter("age");
          String address = request.getParameter("address");
  
             for (String skills : skill) {
              if (csvSkills.length() &gt; 0) {
                  csvSkills.append(",");
                  csvSkills.append(skills);
              }
              String csvSkill = csvSkills.toString();
  
              GetsSets sets = new GetsSets();
              sets.setLname(lname);
              sets.setFname(fname);
              sets.setEmail(email);
              sets.setSkill(csvSkill);
              sets.setAge(age);
              sets.setPassword(password);
              sets.setState(state);
              sets.setAddress(address);
              sets.setGender(gender);
              try {
                  DBManager.Insert(sets);
              } catch (ClassNotFoundException ex) {
                  ex.printStackTrace();
              } catch (SQLException ex) {
                 ex.printStackTrace();
              }
  
          }
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  }
  </code></pre>
  
  <p>These are my Connection Manager:</p>
  
  <pre><code>public class ConnectionManager {
  
      private static ConnectionManager instance = null;
  
      private final String USERNAME = "root";
      private final String PASSWORD = "root";
      private final String CONN_STRING = "jdbc:mysql://localhost/crud_db";
  
  
      private Connection conn = null;
  
      private ConnectionManager() {
  
      }
  
      public static ConnectionManager getInstance() {
          if (instance == null) {
              instance = new ConnectionManager();
          }
          return instance;
      }
  
      private boolean openConnection() {
          try {
              conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
          } catch (SQLException e) {
              e.printStackTrace();
          }
          return true;
      }
  
      public Connection getConnection() {
          if (conn == null) {
              if (openConnection()) {
                  System.out.println("connection openned HE EH EH EHE HEE HE");
                  return conn;
              } else {
                  return null;
              }
          }
          return conn;
      }
      public void close(){
          try {
              conn.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
          conn = null;
      }
  }
  </code></pre>
  
  <p>This is my DBManager:</p>
  
  <pre><code>package org.servlet.java;
  
  import java.sql.Connection;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import java.sql.PreparedStatement;
  import java.sql.SQLException;
  public class DBManager {
  
  private static Connection conn=ConnectionManager.getInstance().getConnection();
  
  public static void Insert(GetsSets set)throws ClassNotFoundException,SQLException{
    // Class.forName("com.mysql.jdbc.Driver");
  
      String sql = "INSERT INTO register (fname,lname,gender,state,email,password,age,address,skill) values(?,?,?,?,?,?,?,?,?)";   
       PreparedStatement pstmt= conn.prepareStatement(sql);
       pstmt.setString(1, set.getFname());
       pstmt.setString(2, set.getLname());
      pstmt.setString(3, set.getGender());
       pstmt.setString(4, set.getState());
       //pstmt.setString(5, set.getCity());
      pstmt.setString(5, set.getEmail());
       pstmt.setString(6, set.getPassword());
       pstmt.setString(7, set.getAge());
       pstmt.setString(8, set.getAddress());
       pstmt.setString(9, set.getSkill());
       pstmt.executeUpdate();
       ConnectionManager.getInstance().close();   // to avoid memory lekage
       }
  }
  </code></pre>
  
  <p>Stuck here since last 4 hours.... Mind is blocked now.... Need serious help.... 
  This is my First servlet example. Page gets redirected, but then it show error in log file  "No suitable driver found for jdbc:mysql://localhost/crud_db"
  Plz... Help me..........</p>