Dato Lee
Chong Wei
Lost Again :(

 

If you know where it's going
it's not worth doing !

29

MAY

2010

Chinese charater in Java, Tomcat, MySQL

Just added a new trade section, dedicated to the sharing of my trading experience and stock selection.

I've decided to write in chinese, so have spent some time to enable chinese character support. Actually it's just 3 simple steps.

Read on for instructions on displaying chinese character for a site powered by Java, Tomcat and Mysql.

Tomcat

In Context.xml, edit Data Source

<...mysql://localhost:3306/db_test?useUnicode=true&characterEncoding=utf-8"/>

If you want chinese charater in URL, like http://www.derekdan.com/trade?tag=手套股, edit the following in Server.xml

<Connector port="80" ... URIEncoding="UTF-8"/>

JSP

<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>

Mysql

Excecute ALTER TABLE for every column that contains chinese character

ALTER TABLE <TABLE_NAME> MODIFY COLUMN <COLUMN_NAME> VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci

Beware that NOT all data type support character set, e.g. BLOB stores data in byte format, so you can't assign any CHARACTER SET to it.

For this reason, previous I was using BLOB type to store my article content, now have to change to TEXT.

Share Article

Rate + Like + Share

Related Posts    

[ + ]

Category    

[ + ]

IT programming (3)

astronomy (1)

auto (2)

broadband (8)

laptop (2)

mobile (2)

property (3)

sports (2)

trade (12)

travel (1)

Related Posts