试试转码:
String newstring = new String(s.getBytes("gb2312"),"ISO8859_1");
其中,s是你要插入到数据库中的字符串。转换后,把newstring插入数据库。你可以搜索一下“中文”或者“转码”,也许会找到些有用的东西。

解决方案 »

  1.   

    我觉得转换成gb2312的编码就行了,没必要再转成ISO8859_1,比如用php操纵mysql时,存入mysql的数据不就是gb2312编码的吗,而且如果再把gb2312编码换成ISO8859_1,可能你用其他程序读数据库时,看到的还是乱码,因为汉字本身就是gb2312编码的。
    其实你就用s.getBytes("gb2312")得到的字节数组写入数据库就行了
      

  2.   

    我想你的程序的运行环境一定是英文的,jdbc向外写数据的时候,会按照一定的编码方式对unicode编码(java中字符的编码方式)进行转换,默认英文环境的转码是按照ISO8859_1进行的,但是unicode没有对应的ISO8859_1编码时,就会转成?字符,所以在使用jdbc时应该设置一下输出的编码方式
      

  3.   

    If your mysql jdbc driver is mm-mysql , please try to add "characterEncoding=GB2312" to the connection string.For more detail , please read the jdbc driver's doc.hope help
      

  4.   

    how to add "characterEncoding=GB2312" to the connection stringplease give us a examplethanks
      

  5.   

    用下面这个url连接就行了jdbc:mysql://[hostname][:port]/dbname?characterEncoding=GB2312
      

  6.   

    最普通的解决方法是用转换函数,存储和取出时转换一下。给你一个函数原型:
    public static String UnicodeToChinese(String s){
      try{
         if(s==null||s.equals("")) return "";
         String newstring=null;
         newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
         return newstring;
        }
      catch(UnsupportedEncodingException e)
      {
      return s;
      }
      }public static String ChineseToUnicode(String s){
      try{
      if(s==null||s.equals("")) return "";
      String newstring=null;
      newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
       return newstring;
      }
      catch(UnsupportedEncodingException e)
      {
      return s;
     }
      }
      

  7.   

    用法说错了
    应该是
    jdbc:mysql://[hostname][:port]/dbname?useUnicode=true&characterEncoding=GB2312楼上的兄弟,你的那个方法对于数据库存取不行,因为编码转换部分是在jdbc驱动内完成的,如果不在取数据的时候设置编码为gb2312,jdbc取数据的时候就会按照错误的编码进行编码转换
      

  8.   

    have some way.where have the driver for db2 and have you the instance about jdbc application for db2 Database.