when i run my code, i get this exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully
I was not unable to figure out the exact cause, but I realized that it was because of some thread pools since I was able to connect to the db using the terminal. for checking the connectivity you can use the below command.
psql -h hostname -U username -d database
so restarting the server worked for me.
DB is down. You must start the DB server and check connectivity with either telnet or mysql command line client first.
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