The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no

 The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no'. The value 'true;characterEncoding=utf-8' is not in this set.

https://blog.csdn.net/sddxqlrjxr/article/details/51868776

以下错误均出现在eclipse使用spring+hibernate访问MySQL数据库的时候。 
eclipse版本:Version: Neon Release (4.6.0) 
spring版本:4.3.0 
hibernate版本:5.2.0 
MySQL版本:5.7.13 
MySQL驱动版本:5.1.39 
spring配置文件名:applicationContext.xml。

<!--定义数据源Bean,使用C3P0数据源实现,并注入数据源必要信息-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"
    p:driverClass="com.mysql.jdbc.Driver"
    p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false"
    p:user="root"
    p:password="1234"
    p:maxPoolSize="40"
    p:minPoolSize="2"
    p:initialPoolSize="2"
    p:maxIdleTime="30" />
1
2
3
4
5
6
7
8
9
10
11
错误一:
Establishing SSL connection without server's identity verification is not recommended. 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.
1
解决方案
p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin"
1
将上面这句换成下面的

p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin?useUnicode=true&characterEncoding=utf-8&useSSL=false"
1
此时错误一将不出意外的消失,但是此时错误二应运而生。

错误二
对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾。
1
解决方案
p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin"
1
将这句再改成下面这样的

p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin?useUnicode=true;characterEncoding=utf-8;useSSL=false"
1
与错误一的解决方案比,就是讲‘&’符号改成了‘;’。 
错误二销声匿迹,错误三粉墨登场。

错误三
The connection property 'useUnicode' only accepts values of the form: 'true', 'false', 'yes' or 'no'....
1
解决方案
p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin"
1
把这句话再改一下

p:jdbcUrl="jdbc:mysql://localhost:3306/ShuziYingxin?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false"
1
就是既不能用‘&’也不能用‘;’而是要使用‘&amp;’。虽然&amp; 本身表示‘&’符号,但是必须这么写才可以,否则解析xml文件时就无法解析。

猜你喜欢

转载自blog.csdn.net/zflb2008/article/details/90715231
今日推荐