使用 getBytes("iso-8859-1"),"gb2312" 方法仍出现乱码的解决方法
2011-11-11 09:57
543 查看
新手学JAVA,从数据库取出数据后,中文格式的数据显示为乱码,按网上找了解决方法:
String Name=rs.getString("UserName");
try{
Name=new String(Name.getBytes("iso-8859-1","gb2312");
}
catch(Exception _ex){}
这是网上解决数据库数据读出的乱码最多的方法,但我试了很多次都不行。最后发现使用下面方法就解决了:
String name1="";
try{
name1 = new String(rs.getBytes("UserName"), "gb2312");
}
catch(Exception _ex){}
最后终于解决!
当然rs.getBytes("UserName"), "gb2312")换成rs.getBytes(2), "gb2312")也可以。
另外使用new String(“”,“”)方法必须放在try{}catch{}里。
String Name=rs.getString("UserName");
try{
Name=new String(Name.getBytes("iso-8859-1","gb2312");
}
catch(Exception _ex){}
这是网上解决数据库数据读出的乱码最多的方法,但我试了很多次都不行。最后发现使用下面方法就解决了:
String name1="";
try{
name1 = new String(rs.getBytes("UserName"), "gb2312");
}
catch(Exception _ex){}
最后终于解决!
当然rs.getBytes("UserName"), "gb2312")换成rs.getBytes(2), "gb2312")也可以。
另外使用new String(“”,“”)方法必须放在try{}catch{}里。
相关文章推荐
- 在JSP中,使用get提交方式出现乱码时,为什么要使用new String(s.getBytes("iso-8859-1"),"utf-8");?
- page = new String(request.getQueryString().getBytes("ISO-8859-1"),"GBK");解决前台传后台乱码问题
- Some characters cannot be mapped using "ISO - 8859 -1" character encoding 解决方法
- 关于保存*.js是出现some character can not mapped using "iso-8859-1" 的问题解决见解
- values[i] = new String(values[i].getBytes("ISO-8859-1"),"utf-8")中文乱码
- MyEclipse编辑js的时候出现some characters cannot be mapped using "ISO-8859-1" charater encoding
- MyEclipse问题:some characters can not mapped using "iso-8859-1" character encoding 解决方法
- 用MyEciplse时 some character can not mapped using "iso-8859-1" character encoding 解决
- 用 MyEciplse时 some character can not mapped using "iso-8859-1" character encoding 解决
- Gradle 使用Jetty插件启动web项目时出现"java.lang.OutOfMemoryError: PermGen space"解决方法
- filename=new String(filename.getBytes("iso8859-1"),"utf-8") 解决乱码
- ISE10.1中复数乘法器IP核使用ModelSim仿真时出现“Module 'CMPY_V2_1' is not defined.”错误的解决方法
- win 7 删除了用户文件夹后出现的"你已使用临时配置文件登录"提示的解决方法
- MyEclipse问题:some characters can not mapped using "iso-8859-1" character encoding 解决方法
- VC 使用MSXML创建SVG文档中的新结点时出现xmlns="" 属性解决方法
- 在asp.net中使用ajax时出现的"'Sys' 未定义"的解决方法
- C#使用String.Format()方法时,出现异常"输入的字符串格式有误"的解决方法
- 分享 返回分享首页» 分享 new String(getBytes(ISO-8859-1),GBK)解决中文乱码问题分析
- 用MyEciplse时 some character can not mapped using "iso-8859-1" character encoding 解决
- 用MyEciplse时 some character can not mapped using "iso-8859-1" character encoding 解决