Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException报错

朴灿烈づ我的快乐病毒、 2022-12-11 15:23 277阅读 0赞

写了Controller类返回json数据文件时候报错
在这里插入图片描述

This application has no explicit mapping for /error, so you are seeing this as a fallback.

在这里插入图片描述

回到idear发现报错:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
The error may exist in edu/xalead/dao/ItemDao.java (best guess)
The error may involve edu.xalead.dao.ItemDao.selectAll
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain 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)

猜测应该是数据库连接的问题,去application.yaml文件下查看数据库连接。

  1. spring:
  2. application:
  3. name: item-service
  4. datasource:
  5. url: jdbc:mysql://localhost:3306/

路径不完整所以连接有问题

  1. spring:
  2. application:
  3. name: item-service
  4. datasource:
  5. url: jdbc:mysql://localhost:3306/jdd

补全你的数据库路径,结果还是发现同样的错误!

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain 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)

再看一遍,原来是数据库的用户名和密码的错误!
这波啊,这波是一石二鸟…

  1. datasource:
  2. url: jdbc:mysql://localhost:3306/jdd
  3. username: root
  4. password:

把自己的数据库密码和用户名校正就好了!

最后在刷新一下网页,返回的数据与数据库中的数据匹配即成功。
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,277人围观)

还没有评论,来说两句吧...

相关阅读