常见异常
以下是我遇到的不知道怎么解决异常
java.sql.SQLException: Access denied for user ‘username’@‘localhost’ (using password: YES)
ERROR [Druid-ConnectionPool-Create-1833789138] - create connection error, url: jdbc:mysql://localhost:3306/spring?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true, errorCode 1045, state 28000
解决
- 我原来配置数据库的db.properties是这样的
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/spring?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username=root
password=123456
而Spring规定的db.properties中的key必须加上jdbc.
2. 修改后
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
jdbc.username=root
jdbc.password=123456
这样之后就可以正常运行了