插入数据库中文乱码

传汉字到mysql数据库,显示问号的解决方法

1、检查jsp显示页面,检查jsp开头有没有设置UTF-8的字符集

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

2、检查后台逻辑代码
根据前台展示页面,找到后台代码,
一般设置编码有如下几种方式:
设置request

request.setCharacterEncoding("UTF-8");

设置response

response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
response.setHeader("Content-Type","text/html;charset=UTF-8");

3、检查数据库字符集
mysql中可以设置数据库字符集,

也可以设置表的字符集

4、变更数据库URL
在连接数据库的URL属性中添加useUnicode=true&characterEncoding=utf8
我直接添加的characterEncoding=utf8
最终解决了我的中文乱码问题

原文地址:https://www.cnblogs.com/Schrodinger6/p/11342422.html