How to save special characters in database

Post Reply
brid.surapol
Posts: 150
Joined: 11 Apr 2013, 11:43

How to save special characters in database

Post by brid.surapol »

Database Level -> UTF-8

Code: Select all

CREATE DATABASE 'db' CHARACTER SET 'utf8';
Table Level -> UTF-8

Code: Select all

CREATE TABLE  `Table1` (
    [...]
) DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
java startup options
#1

Code: Select all

java -Dfile.encoding=UTF-8 [...]
or programmatically
#2

Code: Select all

System.setProperty("file. Encoding" , "UTF-8");
วิธีแรกดีกว่า เพราะ jvm ทำการ cache ค่าของ default character encoding ตอน startup
Post Reply

Return to “การใช้งาน Java และ JVM”