title: Communications link failure due to underlying exception: Connection Time Out
body: <p>My application runs on Linux Mandriva and can't get a connection to the MySQL database.</p>
  
  <p>Part of my.cnf:</p>
  
  <pre><code>bind-address="127.0.0.1"
  # skip- networking
  </code></pre>
  
  <p>I setted <code>wait_timeout</code> as follows:</p>
  
  <pre><code>SET GLOBAL wait_timeout = 28800;
  </code></pre>
  
  <p>I trying to get a connection to the database:</p>
  
  <pre><code>public class TestJdbc {
      public static void main(String[] args) {
          Connection conn = null;
  
          String url = "jdbc:mysql://localhost:3306/";        
          String driver = "com.mysql.jdbc.Driver";
  
          String dbName = "gibrid", userName = "java", 
              password = "java";      
  
          try {
              Class.forName(driver).newInstance();
              conn = DriverManager.getConnection(url+dbName, userName, password);
              System.out.println("Connected to the database");
              conn.close();
              System.out.println("Disconnected from database");
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>I packed this class in jar and send to the server. When I try to execute it, I get the following:</p>
  
  <pre><code>    com.mysql.jdbc.CommunicationsException: 
  Communications link failure due to underlying exception:
  
      ** BEGIN MESSAGE **
  
      java.net.ConnectException
      MESSAGE: Connection timed out
  
      STACKTRACE: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:333)
        ...
  </code></pre>
  
  <p>But when I run this code from my localhost, everything is OK:</p>
  
  <pre><code>Connected to the database
  Disconnected from database
  </code></pre>
  
  <p>What could be the problem?</p>