数据库密码正确,为什么会报错

问题遇到的现象和发生背景

HTTP Status 500 – Internal Server Error

Type 异常报告

消息 Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

描述 服务器遇到一个意外的情况,阻止它完成请求。

Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

The error may exist in com/itheima/core/dao/UserDao.xml

The error may involve com.itheima.core.dao.UserDao.findUser

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))

org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

img

操作环境、软件版本等信息
尝试过的解决方法
我想要达到的结果

密码是a123456吗,你的url检查一下,还有就是mysql的版本,有的带cj有的不带cj,都看一下

如果数据库版本是5.x版本的,将如图中的代码去掉

img

可能原因:jdbc获取数据库连接失败,
1.检查数据库密码
2.检查驱动
3.检查数据库版本和自己的是否一致
4.检查依赖导入是否正常,jar包有无损坏,有时网络卡顿jar包会下载失败
5.检查数据库连接是是否设置时区为UTC
6.检查/itheima/core/dao/UserDao.xml文件
7.检查 com.itheima.core.dao.UserDao.findUser有无语法错误

试下直接用cmd连接数据库,验证账号密码是否仍可用。

也有说可能是计算机名称是中文导致的

把127.0.0.1改成localhost

八版本的不用cj