package com.cncaihua.caihuadb.util;public class StringFormat {
public static String getGBString( String strEn ) {
String strGB = "";
try {
        byte b[]=strEn.getBytes("ISO-8859-1");
        strGB = new String( b );
        } catch(Exception e) {
       }
       return strGB;
}

public static String getSQLString( String str ) {
StringBuffer sb = new StringBuffer( str );
int occur = 0;
occur = sb.indexOf( "'", 0 );
while( occur >= 0 ) {
sb.replace( occur, occur + 1, "''" );
occur = sb.indexOf( "'", occur + 2 );
}
return sb.toString();
}
}

解决方案 »

  1.   

    录入时候掉
    public String toDB(String s){
    if(s == null)
    return null;
    try{
    String convert = new String(s.getBytes("GB2312"), "ISO8859_1");
    return convert;
    }catch(Exception e){}
    return null;
    }
      

  2.   

    我已经试过了。还是不行啊!录入的时候还是乱七八糟的。我用的是sql server 2000 jdbc
      

  3.   

    调用这个可以,我试过了,呵呵!!!<%! public String convertStr(String str) {
        String newstr = str;
        try {
          newstr = new String(str.getBytes("ISO-8859-1"));
        }
        catch (UnsupportedEncodingException uee) {
          System.err.println("convert error!");
        }
        return newstr;
      }
    %>
      

  4.   

    最终是这样解决的,谢谢各位了!
    <%!
     String ex_chinese(String str)
     {
        if(str==null){
         str  ="" ;
         }
         else{
             try {
               str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
             }
             catch (Exception ex) {
             }
         }
         return str ;
      }
    %>