c3p0的配置过程相关exception的解决

刚学springmvc,原理不难,但是精通确实不容易,刚学就卡在了配置文件这块。

解决千难万险后终于走到数据库连接池这块,也是各种百度各种尝试:

遇到的问题:

1.启动server时抛出的:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through method 'setStudentService' parameter 0;

最后发现是C3P0的jar包没给,下载的c3p0-0912.jar,重启服务正常。

2.接着访问controller时抛出:

Method com/mchange/v2/c3p0/impl/NewProxyPreparedStatement.isClosed()Z is abstract] with root cause。

百度说要更改c3p0版本到0.9.5.2,换c3p0-0.9.5.2.jar,一并下载了mchange-commons-java-0.2.15.jar。

3.再执行controller,抛出:

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.,

将原来的jdbc.properties文件里的driver=com.mysql.jdbc.Driver修改为driver=com.mysql.cj.jdbc.Driver

4.继续执行业务,抛出:

java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)

### 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!

百度搜了很多都没能解决,知道时连接数据库失败了,应该是配置文件的问题,我当前的jdbc.properties的配置

是:

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/xx
username=root
password=12345

对比网上一些配置后修改为

datasource.driver=com.mysql.cj.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/xx
datasource.username=root
datasource.password=12345

相应地修改spring的连接池参数配置,再执行竟然通了。究竟是为什么?没能明白,最后我逐个尝试,发现只要用username就出错,用user或者name都没问题,用xusername或datasource.username或jdbc.username都没问题,所以最后我改成了

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/xx
user=root
password=12345


好了,

结束。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hgd95

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值