MySQLNonTransientConnectionException Could not create connection to database server. Caused by: java.lang.NullPointerException
Which version of mysql-connector-java is on your program? I run your code in my PC, and there is no problem.But I change mysql-connector-java to version 5.1.26, I got the same error. You are using mysql 8.0.11,so you can try to use mysql-connector-java 8.0.11.
By the way , the URL
, you should write like this in version 8
String URL= "jdbc:mysql://127.0.0.1:3306/db_example?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=GMT";
I was facing the same problem what I did is that I just updated to mysql-connector-java-8.0.11
previous was mysql-connector-java-5.1.38
.
Changed
Class.forName("com.mysql.jdbc.Driver");
to
Class.forName("com.mysql.cj.jdbc.Driver");
using mysql-8.0.17.0