星期四, 十一月 11, 2010

MYSQL text column insert into UTF-8 .

注意:
http://dev.mysql.com/doc/refman/5.0/en/blob.html
text is  nonbinary strings is character strings . They have a character set, and values are sorted and compared based on the collation of the character set.

同varchar的行为不同。
table people字段chinese_desc为如下类型
CHINESE_DESC   text          utf8_unicode_ci

所以使用Java查询和插入 UTF-8字段插入汉字需要encoding 为 iso-8859-1
插入代码:
String SQL="update people set chinese_desc='\u9802\u7d44\u5408\u88fd\u9020' where ENG_desc='DJZHZZ' ;";//\u9802\u7d44\u5408\u88fd\u9020
String UTF8=new String(SQL.getBytes("UTF-8"),"ISO-8859-1");
PreparedStatement stmt=conn.prepareStatement("set names latin1");
stmt.execute(UTF8);

读取:

        String value =rset.getString("chinese_desc");   
        String value4 = new String(value.getBytes("ISO-8859-1"),"UTF-8");
      System.out.println(value4+"........");