title: Connecting to local Mysql server from other pc
body: <p>I have an local server which installed apache and mysql servers. both of them works very well. I can display the apache default page on browser fine. And I can manage the mysql database via terminal. All okey for now. But if I try to write code to use my DB. It gives me communication link error.</p>
  
  <p>Here is the simple JAVA code: </p>
  
  <pre><code>public static void main(String[] args) {
  
          String url = "jdbc:mysql://192.168.1.49:3306/test";
          String username = "root";
          String password = "1234";
  
          System.out.println("Connecting database...");
          Connection connection = null;
          try {
              connection = DriverManager.getConnection(url, username, password);
  
              System.out.println("Database connected!");
          } catch (SQLException e) {
              throw new IllegalStateException("Cannot connect the database!", e);
          }
  
      }
  </code></pre>
  
  <p>AND HERE IS THE ERROR:</p>
  
  <p>Connecting database...</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IllegalStateException: Cannot
    connect the database!     at
    servermysql.ServerMysql.main(ServerMysql.java:34) Caused by:
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
    Communications link failure</p>
  </blockquote>
  
  <p>THE SERVER İS UBUNTU 14.04 SERVER</p>
  
  <p>THANK YOU FRİENDS</p>