入库数据中文乱码问题

来源:互联网 发布:中国电视台 知乎 编辑:程序博客网 时间:2024/05/17 21:55

解决办法:进行Base64加密解密解决。
Base64Utils:

public class Base64Utils   {    /**       * @param bstr       * @return String       */      public static String encode(byte[] bstr){           return new sun.misc.BASE64Encoder().encode(bstr);       }       /**       * @param str       * @return string       */      public static byte[] decode(String str){           byte[] bt = null;           try {               sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();               bt = decoder.decodeBuffer(str);           } catch (Exception e) {               e.printStackTrace();           }           return bt;       }  }

加密:encode()

String s;Base64Utils.encode(s.getBytes("GBK"));

解密:decode()

String s;Base64Utils.decode(s);