
The driver has not received any packets from the server. Everything worked fine with phpMyAdmin and other applications using PHP but Java applications wouldn’t connect: Exception in thread "main" : Cannot connect the database! at Main.main(Main.java:19) Caused by: .jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago.

MACPORTS EL CAPITAN MAC OS X
It happened to me after updating Mac OS X to El Capitan and upgrading MacPorts to work with it. You may have problems connecting to MySQL from Java applications using Connector/J (the Java connector for MySQL) after upgrading/migrating MacPorts to a newer version.

Fix “Communications link failure” in Java applications with MySQL
