I encountered a hole today, just climbed out and filled it to benefit others.
In the project, when connecting to the database, the following exception was reported
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)] with root cause
java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
......
Baidu this error, there are many online about modifying mysql password, and modifying permissions;
But it doesn't apply to me. The reason why I didn't change it is for two reasons:
One is because when I installed mysql, I could log in successfully with the root user name and root password.
The second is because I have used jdbc to connect to mysql locally, and it was successful.
So now I can't connect in the project, it's definitely not a database password or permission problem. ( I also hope that you don’t blindly follow the modification after searching for the problem, you should analyze it carefully first, whether other people’s methods are suitable for you )
After careful research, it was discovered that -
In my jdbc.properties configuration file, the jdbc.username line has two spaces at the end! ! !
In fact, if you carefully analyze the error message, you should be able to see that Access denied for user 'root '@'localhost', there are actually two spaces after the root in this sentence.
Summary: properties configuration file, do not have spaces at the end of a single line!