问题描述
我正在尝试将阿拉伯字母插入到mysql数据库中,但它只存储????。我使用DBCP连接mysql数据库,这里是数据源:
I am trying to insert Arabic letter in to mysql database, but it only store "????". I am using DBCP for connecting with mysql databse, here is the datasource:
<Resource name="jdbc/view_db"
auth="Container"
type="javax.sql.DataSource"
username="root"
password=""
autoReconnect="true"
testOnBorrow="true"
validationQuery = "SELECT 1"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/view_db"
maxActive="50"
maxIdle="10"/>
如何在DBCP配置中设置UTF-8编码或如何使用(useUnicode = yes characterEncoding = UTF-8)?
how to setup UTF-8 encoding with in DBCP configuration or how to use (useUnicode=yes characterEncoding=UTF-8 ) ?
推荐答案
根据 connectionProperties ,其值为 [propertyName = propertyValue;] *
,所以在你的情况下你应该使用类似的东西:
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"
(注意收盘;
!)
这篇关于如何在DBCP中使用(useUnicode = yes characterEncoding = UTF-8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!