jsp中调用bean:以下是bean里面的方法  
 
 public  void  executeUpdate(String  sql)throws  Exception{  
             sql=new  String(sql.getBytes("GBK"),"ISO8859_1");  
             try{  
                     conn=DriverManager.getConnection(sConnStr,username,password);  
                     Statement  stmt=conn.createStatement();  
                     stmt.executeUpdate(sql);  
                     conn.close();  
                     stmt.close();  
             }  
             catch(SQLException  ex){  
                     System.out.println("sql.executeUpdate:"+ex.getMessage());  
             }  
     }  
这样做也不行!!!

解决方案 »

  1.   

    在构造SQL之前 针对那些参数转码 不要对整条SQL转
     试试吧
      

  2.   

    new String(sql.getBytes("GBK"),"ISO8859_1");  大多数情况下这样做刚刚好搞反了,通常应该是:new String(sql.getBytes("ISO8859-1"),"GBK");另外,这样做编码转换早就过时了,应该使用过滤器。
      

  3.   

    不用转码,在你的jsp中通过response.setCharactEncoding的方法将输出改为GBK或GB2312就行了,另外,注意应当在jsp执行代码的第一行就这么设定。
      

  4.   

    另外,如果你的sql是由上个页面中传过来的,注意也调用request.setCharactEncoding来设定为GBK或GB2312,注意,你上个页面中的charactencoding应当中对应的gbk或gb2312..
      

  5.   

    String str=new String(sql.getBytes("iso-8859-1"),"GB2312");
    这样应该就可以了,这是编码原因造成的。关于过滤器,tomcat下有一个例子。
      

  6.   

    过滤器的例子:
    http://www.blogjava.net/rickhunter/articles/33571.html
      

  7.   

    <%!
    public String GBToUnicode(String strIn)

    String strOut = null; 
    if(strIn == null || (strIn.trim()).equals(""))return strIn; 
    try{ 
    byte[] b = strIn.getBytes("ISO8859_1"); 
    strOut = new String(b,"GBK"); 
    }
    catch(Exception e)
    {} 
    return strOut; 
    }
    %>