2014-10-16 11 views
1

latin1_bin에서 많은 varchar 필드 인코딩을 사용하는 MySQL DB (읽기 전용, DB 변경 없음)가 있습니다. DB 구조를 변경하거나 뷰를 작성할 수 없습니다. 나는 Hibernate를 가지고이 필드에 접근 할 수있다. 최대 절전 모드를 UTF-8로 변환하려면 어떻게해야합니까 ??MySQL latin1_bin with Hibernate를 utf-8로 변환

<property name="hibernate.connection.characterEncoding">UTF-8</property> 

이것은 작동하지 않습니다.

응용 프로그램에서 필드를 직접 변환하지 않으려합니다. 그 이유는 문자열 필드가 너무 많기 때문입니다.

답변 해 주셔서 감사합니다.

답변

0

수동으로 변경할 수 있습니다 latin1_bin 문자열을 utf-8 String.See sample;

public class StringHelper { 
    public static String convertToUTF8(String s) { 
     String out = null; 
     try { 
      out = new String(s.getBytes("ISO-8859-1"), "UTF-8"); 
     } catch (java.io.UnsupportedEncodingException e) { 
      return null; 
     } 
     return out; 
    } 

    public static void main(String[] args) { 
     String latinString = "héllo";//just sample not sure real latin string or not. 
     String utf8String = StringHelper.convertToUTF8(latinString); 
     System.out.println(utf8String); 

    } 

}