zoukankan      html  css  js  c++  java
  • javaWeb-mvc之利用c3p0写入数据库出现乱码

    在使用c3p0向数据库中写入中文数据时出现乱码,于是我采用了和properties中配置url一样

    url=jdbc:mysql://localhost:3306/student?Unicode=true&characterEncoding=utf-8

    配完之后是这样

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 
     3 <c3p0-config>
     4   <named-config name="mvcapp"> 
     5       <property name="user">canon</property>
     6       <property name="password">123456</property>
     7       <property name="driverClass">com.mysql.jdbc.Driver</property>
     8       <property name="jdbcUrl">jdbc:mysql://localhost:3306/customer?unicode=true&characterEncoding=utf-8</property>
     9     <property name="acquireIncrement">50</property>
    10     <property name="initialPoolSize">100</property>
    11     <property name="minPoolSize">50</property>
    12     <property name="maxPoolSize">1000</property>
    13 
    14     <property name="maxStatements">20</property> 
    15     <property name="maxStatementsPerConnection">5</property>
    16 
    17   </named-config>
    18 </c3p0-config>

    但是这样不符合xml的语法,然后就改,加分号什么的,但是没用

    经过查阅资料不应该用Unicode,&需要转义 utf-8和utf8是一样的,不用改也可以

    再次配置

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 
     3 <c3p0-config>
     4   <named-config name="mvcapp"> 
     5       <property name="user">canon</property>
     6       <property name="password">123456</property>
     7       <property name="driverClass">com.mysql.jdbc.Driver</property>
     8       <property name="jdbcUrl">jdbc:mysql://localhost:3306/customer?useUnicode=true&amp;characterEncoding=UTF8</property>
     9     <property name="acquireIncrement">50</property>
    10     <property name="initialPoolSize">100</property>
    11     <property name="minPoolSize">50</property>
    12     <property name="maxPoolSize">1000</property>
    13 
    14     <property name="maxStatements">20</property> 
    15     <property name="maxStatementsPerConnection">5</property>
    16 
    17   </named-config>
    18 </c3p0-config>

    结果:

    ok,乱码问题解决

  • 相关阅读:
    试题 历届试题 国王的烦恼
    试题 历届试题 九宫重排
    试题 历届试题 网络寻路
    试题 历届试题 危险系数
    试题 历届试题 横向打印二叉树
    试题 历届试题 幸运数
    试题 历届试题 大臣的旅费
    试题 历届试题 连号区间数
    Linux多进行之fork
    linux C语言getopt()函数的使用
  • 原文地址:https://www.cnblogs.com/yang--yang/p/4680377.html
Copyright © 2011-2022 走看看