title: No suitable driver found for jdbc mysql?
body: <p>I am trying to write a program to connect to a MySQL database in eclipse, but I get the error <em>"java.sql.SQLException: No suitable driver found"</em>.</p>
  
  <p>The java code is: </p>
  
  <pre class="lang-java prettyprint-override"><code>import java.sql.*;
  
  public class FirstExample {
  
  //static final String S_JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  static final String S_DB_URL = "jdbc:mysql://localhost:3306/emp";
  static final String S_USER = "root";
  static final String S_PASS = "root";
  
  public static void main(String[] args) {
  
      try {
  
          System.out.println("Connecting to database...");
          //Class.forName(S_JDBC_DRIVER);
          Connection connection = DriverManager.getConnection(S_DB_URL,
                  S_USER, S_PASS);
  
          System.out.println("Creating statement...");
          Statement statement = connection.createStatement();
          String sql = "SELECT * FROM Employee";
          ResultSet resultSet = statement.executeQuery(sql);
  
          while (resultSet.next()) {
  
              int iId = resultSet.getInt("id");
              int iAge = resultSet.getInt("age");
              String sFirst = resultSet.getString("fname");
              String sLast = resultSet.getString("lname");
  
              System.out.print("ID: " + iId);
              System.out.print("\tAge: " + iAge);
              System.out.print("\tFirst: " + sFirst);
              System.out.println("\tLast: " + sLast);
          }
  
          resultSet.close();
          statement.close();
          connection.close();
      } catch (SQLException se) {
  
          for (Throwable t : se) {
              t.printStackTrace();
          }
      } 
      System.out.println("Goodbye!");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The output in the console tab is:</p>
  
  <pre><code>Connecting to database...
  java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/emp
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at FirstExample.main(FirstExample.java:21)
  Goodbye!
  </code></pre>
  
  <p>I have used the MySQL Connector/J. It is unzipped in the MySQL installation directory and the jar file is added to the CLASSPATH.</p>
  
  <p>Also refer to this image. There is an ! mark at the project root.<a href="https://docs.google.com/file/d/0B-mhigcuV7cUMnMwN3FuSy0xck0/edit" rel="nofollow">image01</a></p>
  
  <p>I get the error as in the next image: <a href="https://docs.google.com/file/d/0B-mhigcuV7cUNF9ud21iRnNMTEk/edit" rel="nofollow">image02</a> when I include the 2 commented statements:</p>
  
  <pre class="lang-java prettyprint-override"><code>static final String S_JDBC_DRIVER = "com.mysql.jdbc.Driver";
  Class.forName(S_JDBC_DRIVER);
  </code></pre>