자바(Java)/JAVA 2EE

My-SQL 5.1 데이터베이스를 사용할 때 한글이 깨지는 경우

본클라쓰 2010. 1. 26. 18:07

 

My-SQL 5.1 데이터베이스에서 쿼리문이나 결과값에서 한글이 깨지는 경우 문자 인코딩 값이 맞지 않기 때문입니다. 쉽게 해결하는 방법은 컨넥션 객체를 생성할 때 문자 인코딩 값을 지정하는 방법입니다.

 

String mysqlServer = "jdbc:mysql://localhost:3306/데이터베이스명?setUnicode=true&characterEncoding=euckr";
String userid = "데이터베이스 유저ID";
String userpass = "패스워드";

 

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection( mysqlServer, userid, userpass);