temp=chi.getBytes("ISO8859_1");
 
  ----    此为何意?换成temp=chi.getBytes("GBK"); 试试

解决方案 »

  1.   

    http://search.csdn.net/Expert/topic/2237/2237509.xml?temp=.2826807
      

  2.   

    你用的是什么操作系统,看一下编码是什么?
    数据库是什么,知道是什么编码
    最后就是你的编码问题
    具体如下:
    我的数据库SQL Server 2000
    操作系统是win2003
    首先是向数据库插数据乱码
    你看一下是否乱吗
    若不乱
    你试一下转换
    public String trans(String chi)
    {
    String result = null;
                   byte temp [];
                   try
                   {
                           temp=chi.getBytes("gb2312");//主要再这里
                          result = new String(temp);
                    }
                    catch(java.io.UnsupportedEncodingException e)
                    {
                            System.out.println (e.toString());
                    }
    return result;
    }
      

  3.   

    name = new String(result.getString("title").getBytes("gb2312"),"ISO-8859-1");
      

  4.   

    UUBluesky(UUBluesky):我在向数据库中写入时是出现乱码.我现在转码后就没有乱码了,我是用这个转的try
                   {
                           temp=chi.getBytes("ISO8859-1");
                          result = new String(temp);
                    }
    就这样我在写入数据库时不再是乱码了,可是我从数据库中取也时是乱码!不知道什么解决!!!
      

  5.   

    你在
    public void addMessage(){
       try{
           PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");
           stm.setString(1,msg.getTitle());
           stm.setString(2,msg.getName());
           stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
           stm.setString(4,msg.getEmail());
           stm.setString(5,msg.getContent());
           
           stm.executeQuery();
          }catch(Exception e){}
     }
    这里把想存汉字的字段转换了就可以!
    从数据库里取出来的时候就不用转换了!