用这个试试:
String a = "adfafd";
String b = new String(a.getBytes("8859_1"),"GB2312");如果还是不行,用:
String a = "adfafd";
String b = new String(a.getBytes("GB2312"),"8859_1");
String a = "adfafd";
String b = new String(a.getBytes("8859_1"),"GB2312");如果还是不行,用:
String a = "adfafd";
String b = new String(a.getBytes("GB2312"),"8859_1");
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
假如你的client是jsp:
也可以在jsp中加入:
<%@ page contentType="text/html; charset=gb2312" %>来解决中文问题。
是servlet:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
response.setContentType("text/html; charset=gb2312");
然后在 insert into table(...)value(...)