title: Java to Database Connection : Exception
body: <p>I am connecting my java program to mysql database. But i get an exception block executed instead of getting connected i.e, "Connection Failed!!".</p>
  
  <pre><code>  import java.sql.*;
    public class Mysqltest 
   {
  public static void main(String args[])
  {
      String username ="root";
      String password ="bharath12";
      String url ="jdbc:mysql://localhost:3307/";
      String dbName = "sample";
      String driver= "com.mysql.jdbc.Driver";
      Connection con =null;
      try
      {
          Class.forName(driver).newInstance();
          con=DriverManager.getConnection(url+dbName, username, password);
          System.out.println("Connection successfully established.");
          con.close();
          System.out.println("Connection terminated !");
      }
      catch(Exception e)
      {
          System.out.println("Connection failed !!");
      }
  }
      }
  </code></pre>
  
  <p>What would be the error in the above code?
  I deliberately changed mysql port to 3307 during installation (hence, localhost:3307)</p>