中文字符问题,请教,急!! http://community.csdn.net/Expert/topic/3451/3451090.xml?temp=.2846949看看吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我的数据库编码是UTF-8的。输入的是简体中文,在数据库里的是乱码,显示出来的有的是乱码,有的是正常的。 public class ChineseConvertor { /** * */ public ChineseConvertor() { super(); // TODO Auto-generated constructor stub } /** *转换简单字符串 *@param 待转换的字符串 *@return 转换后的字符串 */ public static String ConvertToGBK(String str) { String strReturn=""; try{ strReturn=new String(str.getBytes("ISO-8859-1"),"GBK"); } catch(Exception ex){ System.out.println("TestBean.ConvertGBK():ex="+ex.toString()); strReturn=str; } return strReturn; } /** *转换字符串数组 *@param 待转换的字符串数组 *@return 转换后的字符串数组 */ public static String[] ConvertArrayToGBK(String[] newValue) { for(int i=0;i<newValue.length;i++) { newValue[i]=ConvertToGBK(newValue[i]); } return newValue; } /** *转换简单字符串 *@param 待转换的字符串 *@return 转换后的字符串 */ public static String ConvertToGB2312(String str) { String strReturn=""; try{ strReturn=new String(str.getBytes("ISO-8859-1"),"GB2312"); } catch(Exception ex){ System.out.println("TestBean.ConvertGBK():ex="+ex.toString()); strReturn=str; } return strReturn; } /** *转换字符串数组 *@param 待转换的字符串数组 *@return 转换后的字符串数组 */ public static String[] ConvertArrayToGB2312(String[] newValue) { for(int i=0;i<newValue.length;i++) { newValue[i]=ConvertToGB2312(newValue[i]); } return newValue; }} 插入数据库的时候可以 new String(yourString.getBytes("GBK"));取出数据的时候可以 new String(getString.getBytes(),"GBK"); new String(yourString.getBytes("GB2312")); java 用ztree做动态数 急急急 一个ejb对象为什么不能被并发访问 java调用批处理bat 在JSP中怎么用标签库中迭代标签打印出矩阵? XML封装结构 请教关于spring的remoting.httpinvoker进行远程调用的问题? WSDL2Java类只能生成基本的stub程序问题 小弟就要到北京尖峰计算机系统有限公司,面试! 发表下个人对struts国际化和Tiles标签库的见解,还请指正 [求助]Cookie的问题 如何实现远程调试? 大家好啊,谁有weblogic workshop的教学书
*
*/
public ChineseConvertor() {
super();
// TODO Auto-generated constructor stub
}
/**
*转换简单字符串
*@param 待转换的字符串
*@return 转换后的字符串
*/
public static String ConvertToGBK(String str)
{
String strReturn="";
try{
strReturn=new String(str.getBytes("ISO-8859-1"),"GBK");
}
catch(Exception ex){
System.out.println("TestBean.ConvertGBK():ex="+ex.toString());
strReturn=str;
} return strReturn; }
/**
*转换字符串数组
*@param 待转换的字符串数组
*@return 转换后的字符串数组
*/
public static String[] ConvertArrayToGBK(String[] newValue)
{
for(int i=0;i<newValue.length;i++)
{
newValue[i]=ConvertToGBK(newValue[i]);
}
return newValue;
}
/**
*转换简单字符串
*@param 待转换的字符串
*@return 转换后的字符串
*/
public static String ConvertToGB2312(String str)
{
String strReturn="";
try{
strReturn=new String(str.getBytes("ISO-8859-1"),"GB2312");
}
catch(Exception ex){
System.out.println("TestBean.ConvertGBK():ex="+ex.toString());
strReturn=str;
} return strReturn; }
/**
*转换字符串数组
*@param 待转换的字符串数组
*@return 转换后的字符串数组
*/
public static String[] ConvertArrayToGB2312(String[] newValue)
{
for(int i=0;i<newValue.length;i++)
{
newValue[i]=ConvertToGB2312(newValue[i]);
}
return newValue;
}
}