NutzCN Logo
问答 json接口插入数据库中文乱码
发布于 3038天前 作者 binfoo 2369 次浏览 复制 上一个帖子 下一个帖子
标签:

现象:
1. 数据库中文乱码

  1. 控制台显示中文乱码

  2. 加载的日志

2016-08-28 16:00:42,894 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:174) DEBUG - JDBC URL    --> jdbc:mysql://139.129.118.219:13306/CloudServer
2016-08-28 16:00:42,989 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_client=latin1
2016-08-28 16:00:42,989 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_connection=latin1
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_database=utf8
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_filesystem=binary
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_results=
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_server=latin1
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_set_system=utf8
2016-08-28 16:00:42,990 org.nutz.dao.impl.DaoSupport$1.invoke(DaoSupport.java:183) DEBUG - Mysql : character_sets_dir=/usr/share/mysql/charsets/

怀疑问题出在上面的连接,如何更改

2016-08-28 16:00:41,695 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) DEBUG - Web Container Information:
2016-08-28 16:00:41,704 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) DEBUG -  - Default Charset : UTF-8
2016-08-28 16:00:41,704 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) DEBUG -  - Current . path  : E:\apache-tomcat-8.0.32\bin\.
2016-08-28 16:00:41,705 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) DEBUG -  - Java Version    : 1.8.0_73
2016-08-28 16:00:41,705 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) DEBUG -  - File separator  : \
2016-08-28 16:00:41,705 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) DEBUG -  - Timezone        : Asia/Shanghai
2016-08-28 16:00:41,705 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) DEBUG -  - OS              : Windows 10 amd64
2016-08-28 16:00:41,705 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) DEBUG -  - ServerInfo      : Apache Tomcat/8.0.32
2016-08-28 16:00:41,707 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) DEBUG -  - Servlet API     : 3.1
2016-08-28 16:00:41,707 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:73) DEBUG -  - ContextPath     : /bms
2016-08-28 16:05:16,530 org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:255) DEBUG - INSERT INTO st_relate_user_deviceunitname(deviceId,userid,deviceunitid,deviceunitname,projectname,projectid) VALUES(?,?,?,?,?,?) 
    |   1 |   2 |   3 |   4 |      5 | 6 |
    |-----|-----|-----|-----|--------|---|
    | 180 | 180 | xxx | ooo | 鏈楄瘲鍗楅棬缁块儭 | 2 |
  For example:> "INSERT INTO st_relate_user_deviceunitname(deviceId,userid,deviceunitid,deviceunitname,projectname,projectid) VALUES('180','180','xxx','ooo','鏈楄瘲鍗楅棬缁块儭',2) "
3 回复

入库之前就乱码了

来自炫酷的 NutzCN

先在代码里面做equal判断,确认一下页面传过来的中文是否已经乱码

来自炫酷的 NutzCN

我修改了数据库配置,增加?characterEncoding=utf8后解决
db.url=jdbc:mysql://139.129.118.219:13306/CloudServer?characterEncoding=utf8

添加回复
请先登陆
回到顶部