how to use (useUnicode=yes characterEncoding=UTF-8 ) with DBCP

江枫思渺然 提交于 2019-11-28 06:23:38

According to the DBCP documentation you need use the parameter connectionProperties with value [propertyName=propertyValue;]*, so in your case you should use something like:

      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost/view_db"
      connectionProperties="useUnicode=yes;characterEncoding=utf8;"
      maxActive="50"

(note the closing ;!)

I tried the following and it worked for me using tomcat 7.0.40 and MySQL 5.5 on Debian Wheezy box:

url="jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8" 

Note that & must be represented as &

also make sure that your my.cnf for your mysql server has the following lines:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

Specify it in the url parameter, like this:

url="jdbc:mysql://localhost/view_db?useUnicode=yes&characterEncoding=utf8"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!