public String getUnicode(String str)  throws Exception{
          if(!str.equals("")){
byte[] inputBytes = str.getBytes("8859_1");
str=new String(inputBytes,"GB2312");}
                else
                str="";
return str;
}//end把这个方法写进你的BEAN,再这样调用:
String sql="INSERT INTO `event` ( `id` , `userid` , `when` , `detail` , `comment` , `state` ) VALUES ('', '"+uid+"',NOW(),'"+detail+"', '"+comment+"','"+state+"')";
sql=getUnicode(sql);
sqlbean.execNoResult(sql);

解决方案 »

  1.   

    public static String parseToChinese(String str) { if( str == null ){
    return null ;
    }       String out = str.trim(); if( out.equalsIgnoreCase("")){
    return out ;
    } try{
    out = new String( out.getBytes("ISO8859_1") );
    }catch ( java.io.UnsupportedEncodingException e ){
    e.printStackTrace();
    } return( out );
    }
      

  2.   

    我用的是tomcat要不要什么设置?
      

  3.   

    再在每个页面开头加上
    <%@page contentType="text/html;charset=GBK"%>
    <%request.setCharacterEncoding("GBK");%>
    就没问题了,不用转
      

  4.   

    我用phpmyadmin修改数据库成中文,若没有
    <%@page contentType="text/html;charset=GBK"%>
    则可以正常显示,有也是??
      

  5.   

    在你的连接字符串后面加上
    jdbc:mysql://192.168.0.2:3306/database?useUnicode=true&characterEncoding=GBK这样还不行我去自杀
      

  6.   

    不是吧,我的JSP里面也有这一句啊,
    当我用上面哪个方法转换一下后就可以了这个好像与tomcat没有什么关系呢
      

  7.   

    怎么还没有搞定?不会吧。
    些个测试的页面。
    <html>
    <%@ page language="java" %>
    <%@ page contentType="text/html;charset=gb2312" %>
    public static String parseToChinese(String str) { if( str == null ){
    return null ;
    }       String out = str.trim(); if( out.equalsIgnoreCase("")){
    return out ;
    } try{
    out = new String( out.getBytes("ISO8859_1") );
    }catch ( java.io.UnsupportedEncodingException e ){
    e.printStackTrace();
    } return( out );
    }
    </head>
    <body>
    <%
    String strTest = "这是中文" ;
    strTest = parseToChinese( strTest ) ;
    out.println(strTest) ;
    %>
    </body>
    </html>
      

  8.   

    就是不行啊同志们有空帮我测试一下
    http://218.193.178.125:8083/examples/jsp/project/login.htm
    用hzqq密123456
    源代码在
    ftp://jsp:[email protected]:2121/
    好人做到底吧,我第一次编jsp就遇到这种问题,哎
      

  9.   

    在getAttribute,getParameter之前加上一句request.setCharacterEncoding("gb2312");