title: JDBC + MYSQL Communications link failure
body: <p>I definitely doing something wrong or I missed something but cant figure out what is that. I install XAMPP Apache/MYSQL. I connect locally and everything working fine. I try to make a step farther and get remote access to DB. </p>
  
  <p>PROBLEMS</p>
  
  <ol>
  <li><p>When I type myip/xampp in browser I see only "<strong>The connection was reset</strong>" but for everyone else is OK? (Xampp welcome page)</p></li>
  <li><p>Cant connect via JDBC <code>error com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure</code> when before was working and change only hostname.</p></li>
  </ol>
  
  <p>Here is code.</p>
  
  <pre><code>public DBConnect(String whichDataBase){
      try {
          Class.forName("com.mysql.jdbc.Driver");
          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+whichDataBase+"?characterEncoding=UTF-8","monty","some_pass");
          st = con.createStatement();
      } catch (Exception e) {
          System.out.println("error "+e);}
  }
  </code></pre>
  
  <p>On database status tab its looks like its "connect?" (see host but command=<code>sleep</code> and getting error in java as above). But when I using VPN its connecting and working fine? o_O</p>
  
  <p>Things I've done</p>
  
  <ul>
  <li><p>port forward 80 and 3306 on router (tested on <a href="http://www.yougetsignal.com/tools/open-ports/" rel="nofollow">http://www.yougetsignal.com/tools/open-ports/</a>)</p></li>
  <li><p>changed <code>socket = "TCP/IP"</code> in <code>my.ini</code> </p></li>
  <li><p>comment out <code>#enable-named-pipe</code> and <code>#skip-networking</code></p></li>
  <li><p><code>bind-address="0.0.0.0"</code> (check also <code>127.0.0.1</code>)</p></li>
  <li><p>database user got ALL PRIVILEGES and GRANT on <code>localhost</code> and <code>%</code></p></li>
  </ul>
  
  <p>I'm a beginner so thanks for any help!</p>
  
  <p>EDIT:</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.
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
  at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1036)
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:338)
  at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2232)
  at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
  at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
  at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:790)
  at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:44)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
  at java.lang.reflect.Constructor.newInstance(Unknown Source)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
  at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
  at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at DBConnect.&lt;init&gt;(DBConnect.java:17)
  at Poro.actionPerformed(Poro.java:297)
  at javax.swing.JComboBox.fireActionEvent(Unknown Source)
  at javax.swing.JComboBox.contentsChanged(Unknown Source)
  at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
  at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
  at javax.swing.DefaultComboBoxModel.addElement(Unknown Source)
  at javax.swing.JComboBox.addItem(Unknown Source)
  at Poro.&lt;init&gt;(Poro.java:231)
  at Poro.main(Poro.java:287)
  Caused by: java.net.ConnectException: Connection refused: connect
  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
  at java.net.PlainSocketImpl.connect(Unknown Source)
  at java.net.SocksSocketImpl.connect(Unknown Source)
  at java.net.Socket.connect(Unknown Source)
  at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:213)
  at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:297)
  ... 24 more
  </code></pre>