处理如下:
从数据库中取中文解决方法:
String str=rs.getString(1);
byte[] strbyte=str.getBytes("iso-8859-1");
str=new String(strbyte);
把中文写到数据库中的方法:
String str=text.getText();
byte[] strbyte=str.getByte();
str=new String(strbyte,"iso-8859-1"); 
或者是
str = new String (str.getBytes("ISO-8859-1"),"gb2312");//code convertation

解决方案 »

  1.   

    我这样处理过了,但是还是乱码
    顺便提一下:我从数据库里面提取出的String数据,不做转化就可以输出。但转化为二进制byte[]再转回String来就会出现乱码
    是不是String 和 byte[]中间转化因中文字符的长度等原因造成乱码?
      

  2.   

    你试试看。public static int StringTobytes(String pStrSource,byte[] pbArDest,int piStartPos)
      {
        if(piStartPos<0 || pbArDest == null)
          return 0;
        byte[] bArTemp = pStrSource.getBytes();
        int iNormalLen = bArTemp.length;
        if(pbArDest.length < piStartPos+iNormalLen+2)
          return 0;
        for(int i=0;i<iNormalLen;i++)
          pbArDest[piStartPos+i] = bArTemp[i];
        //the string ending tag '0000'
        pbArDest[piStartPos+iNormalLen] = pbArDest[piStartPos+iNormalLen+1] = (byte)0;    return (iNormalLen+2);
      } public static String bytesToString(byte[] pbArSource,int piStartPos)
       {
        //search for the double zero bytes.
        int iEndPos = -1;
        for(int i = piStartPos;i<pbArSource.length-1;i++)
        {
          if(pbArSource[i] == (byte)0 && pbArSource[i+1] == (byte)0)
          {
            iEndPos = i;
            break;
          }
        }
        if(iEndPos == -1)
          return "";
        String StrTemp = new String(pbArSource,piStartPos,iEndPos - piStartPos);
        return StrTemp;
       }
      

  3.   

    import java.util.*;
    import java.io.*;
    /**
     * This class define two method to change the UTF8 code to GB2312
     * and change the GB2312 to UTF8.
     */
    public class ChangeGB
    {
        /**
         * Get the String from the GB code.
         */
        public static String changeFromGb(String sHTML)
    {
            if(sHTML==null)
    {
    return null;
    }
    StringBuffer svg=new StringBuffer();
    try
    {
    StringBufferInputStream std=new StringBufferInputStream(sHTML);
    BufferedReader bvb=new BufferedReader(new InputStreamReader(std,"GB2312"));
    String tmp=null;
    while((tmp=bvb.readLine())!=null)
    {
    svg.append(tmp);
    }
    std.close();
    bvb.close();
    }
    catch(Exception eee){}
    return svg.toString();
    }
        /**
         * Get the GB code from the String.
         */
    public static String changeToGb(String vvv)
    {
    if(vvv==null)
    {
    return null;
    }
    try
    {
    ByteArrayOutputStream byt= new ByteArrayOutputStream();
    BufferedWriter w = new BufferedWriter(new OutputStreamWriter(byt,"GB2312"));
    w.write(vvv);
    w.flush();
    byte[] bytes=byt.toByteArray();
    StringBuffer svg=new StringBuffer();
    for(int i=0;i<bytes.length;i++)
    {
    svg.append((char)bytes[i]);
    }
    vvv=svg.toString();
    byt.close();
    w.close();
    }
    catch(Exception e){}
    return vvv;
    }
    }
      

  4.   

    多谢了
    我已经解决了
    你们两个都对
    是我搞错了字符串……<@_@>