could not get jdbc connection mysql_Could not get JDBC Connection异常问题

此异常发生在整合SSM过程中.

数据库的properties文件中 用户名的关键词写成了username, 导致报错无法连接

db.properties文件如下:

driver=com.mysql.cj.jdbc.Driver

url=jdbc:mysql:///how2java?serverTimezone=GMT

username=root

password=admin

配置文件如下

异常情况如下:

### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!### The error may exist in file [C:\Users\Tongc\IdeaProjects\ssm_myself\target\classes\mapper\CategoryMapper.xml]

### The error may involve com.cugb.mapper.CategoryMapper.get

### The error occurredwhileexecuting a query

### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

通过网上查找得知:

当出现上面的Exception,而且spring的配置文件如上面两个文件所示时,无法连接数据库的原因在于

这一行因为此时${username}的值并不是jdbc.properties文件中的username值,而是JVM系统环境变量的username。spring容器在管理PropertySource时,不光读取自己写的properties文件,spring也会把JVM system properties和JVM system env properties都读取到容器中,所以请不要使用和JVM properties相同的key。

原文:https://blog.csdn.net/kuohsing/article/details/39452849

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值