您的位置:首页 > 数据库

中文乱码问题

2002-11-19 14:56 399 查看
/*
编码转换,确保写数据库的时候不会出现乱码
*/
package dbJavaBean;

public class CodingConvert
{  
 public CodingConvert()
 {
  //
 }
 public String toGb(String uniStr){
     String gbStr = "";
     if(uniStr == null){
   uniStr = "";
     }
     try{
   byte[] tempByte = uniStr.getBytes("ISO8859_1");
   gbStr = new String(tempByte,"GB2312");
     }
  catch(Exception ex){
    }
     return gbStr;
 }
  
 public String toUni(String gbStr){
     String uniStr = "";
     if(gbStr == null){
   gbStr = "";
     }
     try{
   byte[] tempByte = gbStr.getBytes("GB2312");
   uniStr = new String(tempByte,"ISO8859_1");
     }catch(Exception ex){
    }
    return uniStr;
 }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息