在向数据库中插入数据的时候,中文的时候要进行字符转换!在插入中文的地方调用!
/**** 字符集的转换函数 ****/
// added by baiqing 2003.02.18
public static String charConvert(String strSource){
if (strSource == null){
return "";
}
else{
try{
//return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
System.out.println(str);
return str;
}
catch (Exception ex){
System.out.println(ex.toString());
return "";
}
}
}
/**** 字符集的转换函数 ****/
// added by baiqing 2003.02.18
public static String charConvert(String strSource){
if (strSource == null){
return "";
}
else{
try{
//return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
System.out.println(str);
return str;
}
catch (Exception ex){
System.out.println(ex.toString());
return "";
}
}
}
/**** 字符集的转换函数 ****/
// added by baiqing 2003.02.18
public static String charConvert(String strSource){
if (strSource == null){
return "";
}
else{
try{
//return new String(strSource.getBytes("GB2312"), "ISO-8859-1");
String str = new String(strSource.getBytes("ISO-8859-1"), "GB2312");
System.out.println(str);
return str;
}
catch (Exception ex){
System.out.println(ex.toString());
return "";
}
}
}
顺便也提个问题,如果jsp中 charset=gb2312,还需要这种转换吗?我没有测试过:)
try {
address = new String(str.getBytes("iso-8859-1"), "GB2312");
}
catch (UnsupportedEncodingException ex3) {
}
up一下
顺便也提个问题,如果jsp中 charset=gb2312,还需要这种转换吗?我没有测试过:)
否则,就要用String str= new String(str.getBytes("iso-8859-1"), "GB2312");进行一下转换一下。