Page 1 of 1

How to save special characters in database

Posted: 21 Jun 2023, 23:22
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