title: java.sql.SQLException: No suitable driver found
body: <p>I am trying to execute simple query using below DbQuery.java class which uses DbConnector to get a Connection from DriverManager. </p>
  
  <p><strong>note</strong>: </p>
  
  <ol>
  <li>I have already included "mysql-connector-java-5.1.25-bin.jar" on my
  classpath via: export
  CLASSPATH=$CLASSPATH:/home/me/ocpjp/chapter-10/mysql-connector-java-5.1.25/mysql-connector-java-5.1.25-bin.jar</li>
  <li>I am able to connect to mysql with "mysql -uroot -ptcial
  addressBook", if it matters. </li>
  <li>have also tried running with '-cp'
  argument with no avail.</li>
  <li>I am able to get my #3 DbConnect.java class to say "Database connection established". </li>
  <li>Also #4 <strong>DbQueryWorking.java has no issues</strong> and provides expected output .</li>
  </ol>
  
  <p>Can you please help me understand what is the issue here ?</p>
  
  <p>1) DbConnector.java</p>
  
  <pre><code>package com.me.ocpjp.chapter10;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  
  public class DbConnector{
  public static Connection connectToDb() throws SQLException{
  String url = "jdbc:mysql//localhost:3306/";
  String db = "addressBook";
  String username = "root";
  String password = "tcial";
  return DriverManager.getConnection(url+db, username, password);
  }
  
  }
  </code></pre>
  
  <p>2) DbQuery.java</p>
  
  <pre><code>package com.me.ocpjp.chapter10;
  
  import java.sql.Connection  ;
  import java.sql.Statement  ;
  import java.sql.ResultSet  ;
  import java.sql.SQLException  ;
  import com.me.ocpjp.chapter10.DbConnector;
  
  public class DbQuery{
  public static void main(String[] args){
  try(Connection connection = DbConnector.connectToDb();
          Statement statement = connection.createStatement();
          ResultSet resultSet = statement.executeQuery("select * from contact")){
  System.out.println("ID \tfName \tlName \temail \t\tphoneNo");
  while(resultSet.next()){
  System.out.println(resultSet.getInt("id") + "\t"
  + resultSet.getString("firstName") + "\t"
  + resultSet.getString("lastName") + "\t"
  + resultSet.getString("email") + "\t"
  + resultSet.getString("phoneNo") );
  }
  
  }catch(SQLException sqle){
  sqle.printStackTrace();
  System.exit(-1);
  }
  
  }
  }
  </code></pre>
  
  <p>3) DbConnect.java</p>
  
  <pre><code>package com.me.ocpjp.chapter10;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  
  
  
  public class DbConnect{
  public static void main(String[] args){
  
  String url = "jdbc:mysql://localhost:3306/";
  String database = "addressBook";
  String userName = "root";
  String password = "tcial";
  
  try(Connection connection = DriverManager.getConnection(url+database, userName, password)){
  System.out.println("Database connection established");
  }catch(Exception e){
  System.out.println("Database connectioni NOT  established");
  e.printStackTrace();
  }
  
  }
  
  }
  </code></pre>
  
  <p>4) DbQueryWorking.java</p>
  
  <pre><code>package com.me.ocpjp.chapter10;
  
  import java.sql.Connection  ;
  import java.sql.Statement  ;
  import java.sql.ResultSet  ;
  import java.sql.SQLException  ;
  import java.sql.DriverManager;
  
  public class DbQuery{
  public static void main(String[] args){
  String url = "jdbc:mysql://localhost:3306/";
  String database = "addressBook";
  String userName = "root";
  String password = "tcial";
  try(Connection connection = DriverManager.getConnection(url + database, userName, password);
          Statement statement = connection.createStatement();
          ResultSet resultSet = statement.executeQuery("select * from contact")){
  System.out.println("ID \tfName \tlName \temail \t\tphoneNo");
  while(resultSet.next()){
  System.out.println(resultSet.getInt("id") + "\t"
  + resultSet.getString("firstName") + "\t"
  + resultSet.getString("lastName") + "\t"
  + resultSet.getString("email") + "\t"
  + resultSet.getString("phoneNo") );
  }
  
  }catch(SQLException sqle){
  sqle.printStackTrace();
  System.exit(-1);
  }
  
  }
  }
  </code></pre>