package com.yourcompany.struts.util; import java.io.UnsupportedEncodingException; public class Exchange { public static final String ENCODE = "ISO-8859-1"; public static final String CNCODE = "gbk"; public static String toCn(String value) { String cnString; try { cnString = new String(value.getBytes(ENCODE), CNCODE); return cnString; } catch (UnsupportedEncodingException e) { // TODO 自动生成 catch 块 e.printStackTrace(); return null; } } }
package com.core; public class ChStr { public static String toChinese(String strvalue) { try { if (strvalue == null) { return ""; } else { strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK").trim(); return strvalue; } } catch (Exception e) { return ""; } }
首先你要看看你的编码格式SQL的默认编码格式好象是UTF-8!