ITPub博客

首页 > 应用开发 > IT综合 > 中文乱码问题 (转)

中文乱码问题 (转)

原创 IT综合 作者:amyz 时间:2007-10-09 09:35:05 0 删除 编辑
中文乱码问题 (转)[@more@]

/*
编码转换,确保写数据库的时候不会出现乱码
*/
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;
 }
}


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-975380/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3982
  • 访问量
    7897489