第2个回答 2012-06-12
java里乱码处理有个方法 别人给我的 你试试
public static void testCode(String text)
{
String[] srcCode={"gbk","gb2312","utf-8","iso8859-1","latin1"};
String text1;
try
{
for(int i=0;i<srcCode.length;i++)
{
text1=new String(text.getBytes(),srcCode[i]);
logger.info(srcCode[i]+":"+text1);
}
for(int i=0;i<srcCode.length;i++)
{
for(int j=0;j<srcCode.length;j++)
{
text1=new String(text.getBytes(srcCode[i]),srcCode[j]);
logger.info(srcCode[i]+","+srcCode[j]+":"+text1);
}
}
text1=java.net.URLDecoder.decode(text);
logger.info(text1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
方法里面的参数是你的存入值类,然后对字符进行转码;
你也可以用String c=new String(text.getByte("a"),"b");
然后打印下 System.out.println(a);
a,b为编码方式
text为你存入数据库的数据本回答被提问者采纳
第3个回答 2012-06-07
C#对中文的编码造成的原因。
1)首先还是设定连接字符集,以确认收到的字符的编码方式。
2)把GetString得到的字符串转换到byte数组中。
3)使用Systec.Text.Encoding包中相应字符集的解码方法GetString得到新的字符串。
使用System.Text.Encoding的默认字符集。连接数据库时,设置数据库连接字符集使用的SQL指令strSetCharset为如下值:
string strSetCharset = “Set Names ” + System. Text. Encoding .Default. HeaderName;
在获取数据时,使用下面的函数得到真正的字符串:
private string DBStringToNormal(string dbStr)
{
byte[] str = new byte[dbStr.Length];
for (int i = 0; i < dbStr.Length; ++i)
str[i] = (byte)(dbStr[i]);
return System.Text.Encoding.Default.GetString(str, 0, dbStr.Length);
}本回答被网友采纳