How to Fix Exception in thread “main“ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications

this problem is in the database connection failure, looked up from the Internet, the solution is varied, there are configuration files, and change the code. But everyone makes the same mistake for different reasons.

will be stupid, suddenly realized that the database can not connect, either url, or a user name or password. Turning back, the real cause was found…

error code:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=true";
String username="root";
String password="123456";

remove (with warning) or change to false after url:

String url="jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8&useSSL=false";
String username="root";
String password="123456";

is not an error, you can query out.

Read More: