public static String quoteStringSQL(String s){
  if (s == null) {
    return "NULL";
  }
  int length=s.length();
  StringBuilder buff=new StringBuilder(length + 2);
  buff.append('\'');
  for (int i=0; i < length; i++) {
    char c=s.charAt(i);
    if (c == '\'') {
      buff.append(c);
    }
 else     if (c < ' ' || c > 127) {
      return "STRINGDECODE(" + quoteStringSQL(javaEncode(s)) + ")";
    }
    buff.append(c);
  }
  buff.append('\'');
  return buff.toString();
}

public static String quoteStringSQL ( String s ) { if ( s == null ) { return "NULL" ; } int length = s . length ( ) ; StringBuilder buff = new StringBuilder ( length + 2 ) ; buff . append ( '\'' ) ; for ( int i = 0 ; i < length ; i ++ ) { char c = s . charAt ( i ) ; if ( c == '\'' ) { buff . append ( c ) ; } else if ( c < ' ' || c > 127 ) { return "STRINGDECODE(" + quoteStringSQL ( javaEncode ( s ) ) + ")" ; } buff . append ( c ) ; } buff . append ( '\'' ) ; return buff . toString ( ) ; }
convert a string to a sql literal . null is converted to null . the text is enclosed in single quotes . if there are any special characters , the method stringdecode is used .
