出现这个前提是高版本mysql驱动,mysql-connector-java版本高和版本低的配置不同!不同!不同!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC"-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<!--通过这个配置文件,完成mybatis与数据库的连接 -->
<configuration>
<environments default="">
<environment id="">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver"value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/tdoke-iot?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false" />
<property name="username" value="root" />
<property name="password" value="root" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper class="com.tdoke.mapper.DeviceMapper"/>
<mapper resource="mapper/DeviceMapper.xml"/>
</mappers>
</configuration>
上面 jdbc:mysql://localhost:3306/tdoke-iot?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false 是解决的结果,贴上可以解决你的问题,下面讲问题在哪
1. 如果jdbc:mysql://localhost:3306/tdoke-iot?characterEncoding=utf-8只写到这里,报下面的错:
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException:
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
2.加上&serverTimezone=UTC&useSSL=false;可以保证你xml里面配置不报错,然后关键的是这句serverTimezone=UTC
这是因为为了使MySQL JDBC驱动程序与UTC时区配合使用,必须在连接字符串中明确指定serverTimezone
就是这句话
你加上就好了
?characterEncoding=utf-8&serverTimezone=UTC&useSSL=false
网友评论