.xml配置文件中The reference to entity "characterEncoding" must end with the ';' delimiter.错误

写JavaWeb小项目的时候,需要配置c3p0-config.xml,eclipse上总是有个×,配置文件如下:

<c3p0-config>
  <default-config>
    <property name="driverClass">com.mysql.cj.jdbc.Driver</property>
    <property name="jdbcUrl">jdbc:mysql://localhost/stus?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT</property>
    <property name="user">root</property>
    <property name="password">root</property>
    
    <property name="initialPoolSize">10</property>
    <property name="maxIdleTime">30</property>
    <property name="maxPoolSize">100</property>
    <property name="minPoolSize">10</property>
    <property name="maxStatements">200</property>
  </default-config>

</c3p0-config>

很是让人抓狂!!!
通过使用xml格式化在线工具,报错:

Error on line 4 of document : The reference to entity "characterEncoding" must end with the ';' delimiter. Nested exception: The reference to entity "characterEncoding" must end with the ';' delimiter.

百度一下,发现问题如下:

这个错误是转义字符的问题

在.xml文件中有五种字符必须转义才能使用
 1. &gt; ==  >  大于号

 2. &lt;  ==  <  小于号

 3. &amp; == &  和

 4. &apos; == '  单引号

 5. &quot; == "  双引号

我出现这个错误就是由于配置文件中的连接驱动是:
jdbc:mysql://localhost/stus?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
中间有个两个&, 故报错

转义成 &amp;即可解决

发布了32 篇原创文章 · 获赞 3 · 访问量 1355

猜你喜欢

转载自blog.csdn.net/weixin_44270855/article/details/104223148