when i run my code, i get this exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully
There is CommunicationsException: Communications link failure.
If you get a SQLException: Connection refused or Connection timed out or a MySQL specific
CommunicationsException: Communications link failure
then it means that the DB isn't reachable at all. This can have one or more of the following causes:
To solve the one or the other, follow the following advices:
Source: More Details