Use today IDEA Create a normal Java engineering , And use JDBC Test connection database , Run time error “com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. ”
Du Niang inquired , I found a lot of them because they were installed mysql drive Follow mysql8.0 Caused by mismatch , Check the installation on your computer mysql Is, indeed, 8.0, The driver is provided in a tutorial 5.0 Of sql drive , From the website https://dev.mysql.com/downloads/connector/j/ To download the latest matching mysql drive
Update in project sql Drive to 8.0 After running again, it still reports an error , The driver name I used is out of date , The new driver class is “com.mysql.cj.jdbc.Driver”, instead of “com.mysql.jdbc.Driver” 了 , And said I didn't have a configuration timezone, Checked the , Originally from JDBC6.0 Start using the new driver class , also url Time zone must be set in , No side will report an error .
Update to the following as prompted , The database can be accessed and updated normally
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mytestdb?useSSL=false&serverTimezone=UTC", "root", "root");