Home > Database > Mysql Tutorial > mysql中文字符编码问题_MySQL

mysql中文字符编码问题_MySQL

WBOY
Release: 2016-06-01 13:43:44
Original
1039 people have browsed it

bitsCN.com create database 的时候写上
        default character set gb2312
 
java内部是unicode,连接的时候写上数据库的默认字符编码
        //数据库建立的默认编码为gb2312
        conn = DriverManager.getConnection("jdbc:mysql://" + Host + "/" + DBName + "?user=" + User + "&password=" + Password + "&useUnicode=true&characterEncoding=gb2312");
 
这样,直接在sql语句中使用java字符串,java会在与mysql的通讯中进行正确的编码转换,将unicode编码转换成gb2312编码。
 
最后,如果写servlet,还要写上这句话
        response.setContentType("text/html");
        response.setCharacterEncoding("GB2312"); bitsCN.com

Related labels:
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