title: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link failure
body: <p>My program that connects to a MySQL database was working fine. Then, without changing any code used to set up the connection, I get this exception:</p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  
  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  </code></pre>
  
  <p>What happened?</p>
  
  <p>The code used to get the connection:</p>
  
  <pre><code>private static Connection getDBConnection() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
      String username = "user";
      String password = "pass";
      String url = "jdbc:mysql://www.domain.com:3306/dbName?connectTimeout=3000";
  
      Class.forName("com.mysql.jdbc.Driver");
      Connection conn = DriverManager.getConnection(url, username, password);
      return conn;
  }
  </code></pre>