Solution to Caused by: java.lang.NullPointerException

Discover

After getting the project from the teacher, it was normal when the project started, but when the data was submitted on the web page, Caused by:

java.lang.NullPointerException

insert image description here

An error is reported,
the last log shows

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

It was caused by a bug when connecting to mysql.
After checking, it was a database version mismatch problem,
so I checked the mysql version of my computer.

insert image description here

Wow, it's mysql8.0, let's look at the mysql version in the dependencies

insert image description here
It is mysql5.1.32, the two versions do not match,

Solution

Because the mysql installed in my computer is version 8.0, the version in the pom dependency is also changed to 8.0, and mysql8.0.24 version is used here
insert image description here

Then modify the connection pool driver, mysql8.0 can not use the original wording, add cj on the basis of "com.mysql.jdbc.Driver"

com.mysql.cj.jdbc.Driver

insert image description here
Hey, it was finally solved perfectly, congratulations (o°ω°o)

Guess you like

Origin blog.csdn.net/qq_49868778/article/details/129680570