title: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver error even after importing library
body: <p>I have imported my library "mysql-connector-java-5.1.39"
  as answered by most people to exact same question , 
  but I am still getting this error</p>
  
  <pre><code>java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
  </code></pre>
  
  <p>here is the code of test class </p>
  
  <pre><code>package database;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  public class Main {
  
      public static void main(String[] args) throws Exception {
          getConnection();
      }
  
      public static Connection getConnection() throws Exception {
          try{
              String driver="com.mysql.jdbc.Driver";
              String url="jdbc:mysql://localhost:3306/test";
              String username="root";
              String password="root";
              Class.forName(driver);
              Connection conn= DriverManager.getConnection(url,username,password);
              System.out.println("connected");
              return conn;
          }
          catch (Exception e){
              System.out.println(e);
          }
          return null;
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VUh67.png" rel="noreferrer"><img src="https://i.stack.imgur.com/VUh67.png" alt="eclipse directory"></a></p>
  
  <p>Using mac OS .</p>