mysql could not create connection_MySql :Could not create connection to database server.

错误:

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

### The error may exist in cn/action/dao/UserDao.xml

### The error may involve cn.action.dao.UserDao.findList

### The error occurred while executing a query

### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)

at cn.action.test01.TestSelectList.main(TestSelectList.java:29)

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

原因:

MySql8.0应用低版本jar包,产生错误

解决:

1.下载高版本jar包

可以在官网下载跨平台版本,或在下面连接中下载,

百度网盘:https://pan.baidu.com/s/1xlUg9b6mxzt9fWt0u_7qag

下载后解压:

f4d832e73d52cc5df0f9df0d2765cf93.png

2.更改驱动名

以前:com.mysql.jdbc.Driver

5a52e40c2832b387e32ad55d782efa33.png

更改后:com.mysql.cj.jdbc.Driver

a064d8347cb5b4072fa99cbf1d97199a.png

3.删除原来的驱动包

项目上右键->Build Path->Configure Build Path->Libraries中带错误的jar包remove

4.由于版本时区不同,要在数据库后加上“?serverTimezone=UTC"

7d0541e3e26ed1f4f6d18d5a0d957a1f.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值