本人是将mysql中的数据导入到excel中,可惜总是出乱码!!

解决方案 »

  1.   

    mysql 不支持 unicode,所以比较麻烦。
    将 connectionString 设置成 encoding 为 gb2312
    String connectionString
      = "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gb2312";测试代码:
            String str = "汉字";
            PreparedStatement pStmt = conn.prepareStatement("INSERT INTO test VALUES (?)";
            pStmt.setString(1,str);
            pStmt.executeUpdate();数据库表格:
      create table test (
        name char(10)
    ////////////////////////////////////////
    str = new String(str.getBytes("ISO8859_1","gb2312"))
      

  2.   

    将需要写中文的单元格设置为:
    cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      

  3.   

    我使用的是sql2000,这样导入没有问题。