title: SQLException: Communications link failure (Java/mysql)
body: <p>Can someone explain to me why this line works:</p>
  
  <pre><code>conn = DriverManager.getConnection("jdbc:mysql://myWebsite.com:3306/schemaName?user=userX&amp;password=passwordX");
  </code></pre>
  
  <p>But this line does not:</p>
  
  <pre><code>conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/schemaName?user=userX&amp;password=passwordX");
  </code></pre>
  
  <p>I get a Communications Link Failure when attempting to access through the localhost (or 127.0.0.1). However, I'm able to access the database via localhost through PHP and the MySQLQuery Browser and MySQL Aministrator.</p>
  
  <p>If needed here's the entire method I'm using:</p>
  
  <pre><code>public Database() throws Exception {
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  
  try {
    conn = DriverManager.getConnection("jdbc:mysql://myWebsite.com:3306/schemaName?user=userX&amp;password=passwordX");
    // Next line does not work.
    //    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/schemaName?user=userX&amp;password=passwordX");
    } catch (SQLException ex) {
        displaySQLException(ex); // Seperate routine to display errors.
    }
  }
  </code></pre>
  
  <p>Thanks for any help,
  Richard</p>