报错信息
这类报错信息应该是由多种原因造成的,也就是很多原因都将造成这个报错
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
### The error may exist in UserMapper.xml
### The error may involve test.seleceAll
### The error occurred while executing a query...
解决
一、检查配置文件的信息是否完全对应
虽然这个很多人都说,但是先检查这个还是很有必要的,信息错误也会报这个错
配置文件的名字、查询的唯一标签名、mybatis配置文件中数据库的名字、以及数据库的表名等
<dataSource type="POOLED"> <property name="driver" value="com.mysql.cj.jdbc.Driver"/> <!--下一行中的mybatis是数据库的名字(不是表的名字),如果自己的数据库名不是mybatis要改下--> <property name="url" value="jdbc:mysql:///mybatis?useSSL=false"/> <property name="username" value="root"/> <property name="password" value="a1361..."/> </dataSource>
二、检查 Class.forName("com.mysql.cj.jdbc.Driver");能不能运行
将主函数中所有代码注释,加上:
Class.forName("com.mysql.cj.jdbc.Driver");
运行是否报错,如果连这个代码报错:com.mysql.cj.jdbc.Driver
说明mysql包压根没有导进maven
两个原因:
1、提高pom.xml中导入的mysql包的版本,建议8.0.29版本
<groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.29</version>
2、 检查pom.xml中导入的mysql坐标中没有依赖限制,也就是没有
<scope>test</scope>这东西会限制范围,我忘了删...
我的是这两个东西都有问题,解决就没问题了
三、mybatis配置中,url加上时间
这个听别人说的,不过之前应该都用jdbc练习过,当时简短的都可以,这个应该不影响,可以试下
jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC
mybatis配置中改成这个
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC"/>