ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90

๐Ÿ“Œ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

๋„์ปค (Docker) - JDBC๋กœ Ubuntu(tomcat8)์™€ MySQL ์—ฐ๊ฒฐ (tistory.com)

 

๋„์ปค (Docker) - JDBC๋กœ Ubuntu(tomcat8)์™€ MySQL ์—ฐ๊ฒฐ

๐Ÿ“Œ ์ด ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” MySQL ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ƒ์„ฑ๋˜์–ด์žˆ์–ด์•ผํ•œ๋‹ค. ์ƒ์„ฑ์„ ์•ˆ ํ–ˆ๋‹ค๋ฉด ์•„๋ž˜์˜ ํฌ์ŠคํŒ…์„ ์ฐธ๊ณ ํ•ด์„œ ์ง„ํ–‰ํ•˜๊ณ  ๋‹ค์‹œ ๋Œ์•„์˜ค์ž!! ๋„์ปค (Docker) - MySQL ์„ค์น˜ (tistory.com) ๋„์ปค (Docker) - M

programmer-ririhan.tistory.com

 

๐Ÿ’พ ํ•œ๊ธ€ ๊นจ์ง ๋ฌธ์ œ ๋ฐœ์ƒ!!

๋‚˜๋Š” ์ด๋ฏธ ๋‹ค์Œ๊ณผ ๊ฐ™์ด url์— utf-8์— ๋Œ€ํ•œ ์„ค์ •์„ ์ถ”๊ฐ€ํ•ด์„œ ๋ณด๋‚ด๊ณ  ์žˆ์—ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๊ณ„์†ํ•ด์„œ ํ•œ๊ธ€์ด ๊นจ์ง€๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€๊ณ , ์ถ”๊ฐ€์ ์ธ ์„ค์ •์ด ํ•„์š”ํ•ด ๋ณด์˜€๋‹ค..

String dbUrl = "jdbc:mysql://172.17.0.2:3306/about_me_db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=utf8";

 

๐Ÿ’พ MySQL์˜ config ํŒŒ์ผ(my.cnf)์— ์ธ์ฝ”๋”ฉ ์†์„ฑ ์ ์šฉ

# cd /etc/mysql
# nano my.cnf
# for using korean
[mysql]
default-character-set = utf8

[client]
default-character-set = utf8

[mysqld]
character-set-server = utf8
collation-server = utf8_general_ci
init_connect='SET NAMES utf8'

 

๐Ÿ’พ ๋ณ€๊ฒฝํ•œ ์„ค์ •์‚ฌํ•ญ์ด ์ ์šฉ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

# mysql -u root -p

โ—ผ mysql ์†์„ฑ ํ™•์ธ

mysql> status;

 

 

โ—ผ ํ…Œ์ด๋ธ” ์†์„ฑ ํ™•์ธ

mysql> use about_me_db;
mysql> show create table guestbook;

 

๐Ÿ“Œ ํ…Œ์ด๋ธ”์„ ์ƒ์„ฑํ•  ๋•Œ ์บ๋ฆญํ„ฐ ์…‹ ์„ค์ •์„ ํ•ด์ฃผ์ง€ ์•Š์•˜์œผ๋ฉด ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋กœ ์ด๋ฅผ ์„ค์ •ํ•ด์ค€๋‹ค.

mysql> alter table guestbook convert to character set utf8;

 

๋‚˜๋Š”... ๊ทธ๋ž˜๋„ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์ง€ ์•Š์•˜๋‹ค..ใ…œ

 

์ถฉ๊ฒฉ์ .. ๋‹ค์Œ ์ฝ”๋“œ ํ•˜๋‚˜ ์ถ”๊ฐ€ํ•ด์„œ ํ•ด๊ฒฐํ–ˆ๋‹ค^^

 

๐Ÿ’พ ์„œ๋ธ”๋ฆฟ์—์„œ์˜ utf-8 ์„ค์ •

request.setCharacterEncoding("utf-8");

๋‚˜๋Š” ์ง€๊ธˆ๊นŒ์ง€ .jsp ํŒŒ์ผ ์ƒ๋‹จ์— ๋‹ค์Œ๊ณผ ๊ฐ™์ด๋งŒ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋˜๋Š” ์ค„ ์•Œ์•˜๋Š”๋ฐ ์œ„์˜ ์ฝ”๋“œ๋„ ์ถ”๊ฐ€ํ•ด์ค˜์•ผํ•œ๋‹ค.

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

 

mysql๊ณผ tomcat ์„œ๋ฒ„์˜ ์›น ํŽ˜์ด์ง€์—์„œ๋„ ํ•œ๊ธ€์ด ์ž˜ ๋‚˜์˜จ๋‹ค. ์˜ค์˜ˆ!!


Ref.

MySQL ํ•œ๊ธ€ ๊นจ์ง ๋ฌธ์ œ | ๊ธฐ๋กํ•˜๊ธฐ (hongsii.github.io)

java/jsp utf-8๋กœ ํ•œ๊ธ€์ฒ˜๋ฆฌํ•˜๊ธฐ (tistory.com)

 

728x90
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€