title: How to import JDBC driver into Dynamic Web Project?
body: <p>I have a local MySQL database. When I created a simple Java project, with one class which contained only main, I successfully retrieved some data from the database using JDBC connector jar, imported with Build path -> Add external jars, and it worked perfectly.</p>
  
  <p>Then I tried to use a similar approach, but now in a <strong>Dynamic Web Project</strong>, in which I am using Servlets, but I get <strong>java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ePay</strong>.</p>
  
  <p>I have been looking for several hours into the answers of similar questions, and here is where I have tried to put the JDBC MySQL connector so far:</p>
  
  <ol>
  <li>Directly into Java Resources folder</li>
  <li>Into lib folder which is within Java Resources</li>
  <li>Into WebContent/WEB-INF/lib/</li>
  </ol>
  
  <p>Do I need web.xml or context.xml? I read a tutorial in which they were used, tried to implement the explained example, but I still had the same problem.</p>
  
  <p>I am working on Linux Mint 17, using Tomcat 7 into Eclipse IDE.</p>
  
  <p>Here is the photo of my project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/r6Kb0.png" alt="enter image description here"></p>
  
  <p>Here are the relevant classes:</p>
  
  <pre><code>package dbObjects;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  public class Entity {
      protected Connection getConnection() throws SQLException {
          String pass = "mypass";
          String userDB = "root";
          Connection conn = DriverManager.getConnection(
                  "jdbc:mysql://localhost/ePay", userDB, pass);
          return conn;
      }
  
      protected ResultSet getResultSet(String sql) throws SQLException {
          Connection conn = getConnection();
          Statement st = conn.createStatement();
          return st.executeQuery(sql);
      }
  }
  </code></pre>
  
  <p>The user class:</p>
  
  <pre><code>package dbObjects;
  
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.Date;
  
  public class User extends Entity {
      private long idUser;
      private String userName;
      private String pass;
      private String fullName;
      private String email;
      private Date dateOfBirth;
      private String address;
  
      public User(long idUser, String userName, String pass, String fullName,
              String email, Date dateOfBirth, String address) {
          super();
          this.idUser = idUser;
          this.userName = userName;
          this.pass = pass;
          this.fullName = fullName;
          this.email = email;
          this.dateOfBirth = dateOfBirth;
          this.address = address;
      }
  
      public User(long idUser) throws SQLException {
          super();
          this.idUser = idUser;
          setUserById(idUser);
      }
  
      private void setUserById(long idUser) throws SQLException {
          ResultSet resultSet = getResultSet("SELECT * FROM User WHERE idUser = " + idUser);
          while(resultSet.next()) {
              System.out.println(resultSet.getInt("idUser"));
              userName = resultSet.getString("username");
              pass = resultSet.getString("pass");
              fullName = resultSet.getString("fullname");
              email = resultSet.getString("email");
              dateOfBirth = resultSet.getDate("dateOfBirth");
              address = resultSet.getString("address");
          }
      }
  
      @Override
      public String toString() {
          return userName;
      }
  
  }
  </code></pre>
  
  <p>And the servlet which I am trying to run:</p>
  
  <pre><code>package servlets;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.SQLException;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import dbObjects.User;
  
  /**
   * Servlet implementation class HomeServlet
   */
  @WebServlet(description = "Home page shown to user", urlPatterns = { "/HomeServlet" })
  public class HomeServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public HomeServlet() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          User user = null;
          try {
              user = new User(1);
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          PrintWriter pw = response.getWriter();
          pw.println(user);
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
      }
  
  }
  </code></pre>