MySQL乱码问题

 
JSP的request 默认为ISO8859_1,所以在处理中文的时候,
  要显示中文的话,必须转成GBK的,如下
  String str=new String(request.getParameter("name").getBytes("ISO8859-1"),"GBK");
  out.println(str);
  这样就可以显示中文了
  MYSQL操作时的中文问题:
  这个要看MySQL的默认编码了,一般不调整的话为latin1其实和ISO8859_1一样,所以操作的时候要处理
  和他一致,不然就会乱码的
  1.插入中文:
  String sql2="INSERT INTO test (name) VALUES('"+request.getParameter("name")+"')";
  stmt.executeUpdate(sql2);
  不用编码就可以插入了
  2.显示插入的中文:
  因为存入的是latin,所以显示的时候就要GBK一下
  String x=new String((rs.getString("title")).getBytes("ISO8859_1"),"GBK");
  out.println(x);
  3.设定存储编码:
  当然在MySQL为latin1编码时,也可以存的时候用GBK了
  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp?
  useUnicode=true&characterEncoding=GBK","root","");
  str1="中文";
  String sql2="INSERT INTO test (name) VALUES('"+str1+"')";
  这样也可以很成功的插入
 
 
 
http://user.qzone.qq.com/372806800/blog/1336199262
原文地址:https://www.cnblogs.com/amwuau/p/6255508.html