zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    观后感
    用户故事排球教练助手
    本周工作量
    本周个人作业
    个人工作量
    个人作业
    产品计划总结
    典型用户和场景总结
    排球比赛计分规则
    PowerShell ISE:Windows Server 2008 R2默认不安装
  • 原文地址:https://www.cnblogs.com/amwuau/p/6255508.html
Copyright © 2011-2022 走看看