关于mysql驱动版本报错解决,Cause: com.mysql.jdbc.exceptions.jdbc4、Unknown system variable ‘query_cache_size

Error01 针对Maven项目依赖 mysql驱动版本不匹配
querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

在这里插入图片描述

ERR02 mysql驱动版本不匹配
java.sql.Exception in thread “main” java.sql.SQLException: Unknown system variable ‘query_cache_size’

mysql-connecter-java的版本过低,数据库驱动程序与数据库版本不对应

`错误1:
java.sql.Exception in thread "main" java.sql.SQLException: Unknown system variable 'query_cache_size'
`错误2:
java.sql.SQLException: Unknown system variable 'language'

`原因
mysql-connecter-java的版本过低,数据库驱动程序与数据库版本不对应
`解决
1、更换工具包
mysql-connecter-java-5.1.47.jar 可以匹配 mysql8.0+

2、修改 pom文件
如mybatis使用 mysql-5.1.14的驱动程序,而mybatis配置的数据源连接的是 mysql-8.0.11 ,
修改 pom文件,如下:
<dependency>    
    <groupId>mysql</groupId>    
    <artifactId>mysql-connector-java</artifactId>   
    <version>8.0.11</version>  # 改成8.0+版本就可以了。
</dependency>

官方说法:
The query cache is deprecated as of MySQL 5.7.20, and is removed in MySQL 8.0. Deprecation includes query_cache_size.
意思:是查询缓存在MySQL 5.7.20中已弃用,在MySQL 8.0中已被移除。弃用包括query_cache_size。
Error03:jdbc 的 针对于mysql8+版本的URL SSL验证问题
WARN:hu Apr 15 12:27:34 CST 2021 WARN: Establishing SSL connection Establishing SSL connection without server’s identity verificati
hu Apr 15 12:27:34 CST 2021 WARN: Establishing SSL connection Establishing SSL connection without server's identity verificatio
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

在这里插入图片描述

# 解决: 
# 在jdbcURL属性标签中添加这样的一行代码便会跳过SSL验证
?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
例如:
Connection connect = DriverManager.getConnection( 
"jdbc:mysql://localhost:3306/数据库名?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false","root","root");
EER04:junit-4.11以上版本不在包含hamcrest。
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
junit 单元测试报错java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing

Caused by: java.lang.ClassNotFoundException: org.hamcrest.SelfDescribing
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 19 more
原因

junit-4.11以上版本不在包含hamcrest。
解决方法

方法一:junit版本降到4.11以下

方法二:加入hamcrest-core-1.3.jar包
Err05 :属性集配置文件中路径不能有空格,否则报错: org.apache.ibatis.exceptions.PersistenceException ,Error building SqlSession.
org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in configstatic/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'configstatic/UserMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ' com.itheima.mb.pojo.User'.  Cause: java.lang.ClassNotFoundException: Cannot find class:  com.itheima.mb.pojo.User

文件路径不能有空格
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

编程小栈

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

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

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

打赏作者

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

抵扣说明:

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

余额充值