Home > Database > Mysql Tutorial > body text

jsp插入mysql数据库显示中文乱码问题

WBOY
Release: 2016-06-07 15:25:47
Original
1247 people have browsed it

jsp插入mysql时中文显示乱码,查找了一上午资料,现将解决方法记录如下: jsp向mysql插入数据时,在jsp页面上首先设置统一编码:request.setCharacterEncoding(utf-8); 然后在建库和建表时指定统一编码式utf8,式如下: 1、创建数据库的时候:CREATE DATABAS

jsp插入mysql时中文显示乱码,查找了一上午资料,现将解决方法记录如下:

jsp向mysql插入数据时,在jsp页面上首先设置统一编码:request.setCharacterEncoding("utf-8");

然后在建库和建表时指定统一编码格式utf8,格式如下:

1、创建数据库的时候:CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci';
2、建表的时候 CREATE TABLE `database_user` (
`ID` varchar(40) NOT NULL default '',
`UserID` varchar(40) NOT NULL default '',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

修改mysql默认安装目录下的my.ini的文件,将默认的latain1编码格式改为UTF8。

在和mysql建立连接时将url改为如下格式:

url=url=jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF8

这样在连接时即将连接方式改为了UTF8的格式。


在command控制台中通过show variables like 'char%'查看当前默认的连接方式。

通过set character_set_server='utf8';对默认的连接方式进行修改。




source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!