Java Utililty Methods String Quote

List of utility methods to do String Quote

Description

The list of methods to do String Quote are organized into topic(s).

Method

Stringquotes(CharSequence stringToQuote, boolean escapeQuote)
Quotes the given string (eg.
return "'" + (escapeQuote ? escapeQuote(stringToQuote) : stringToQuote) + "'";
Stringquotes(String str)
quotes
return "\"" + str + "\"";
StringquotesEscape(String text)
quotes Escape
if (text.contains(".")) {
    String[] values = text.split("\\.");
    return values[0] + "." + "\"" + values[1] + "\"";
} else {
    return "\"" + text + "\"";
StringQuoteSingle(String S)
Quote Single
return '\'' + S + '\'';
StringquoteSpecial(String orig)
Quote all "special" characters in a query.
if (null == orig) {
    return null;
return orig.replace("\\", "\\\\").replace("'", "\\'");
StringquoteSpecialCharacters(final String oldString)
Quotes the special XML characters present in oldString so the return string can be embedded within an XML document without problems.
final StringBuffer quotedString = new StringBuffer();
if (oldString == null) {
    return null;
for (int i = 0; i < oldString.length(); i++) {
    if (oldString.charAt(i) == '<') {
        quotedString.append("&lt;");
    } else if (oldString.charAt(i) == '>') {
...
StringquoteSQL(String string)
Puts the given String into quotation marks, original quotation marks are escaped
if (string == null)
    return "NULL"; 
return "'" + escapeSQL(string, false) + "'"; 
StringquoteSqlIdentifier(String identifier)
Quote an SQL identifier by enclosing it in double-quote characters and escaping any double-quote characters with an extra double-quote character.
StringBuffer retValue = new StringBuffer(identifier.length() + 2);
final char quote = '"';
retValue.append(quote);
for (int i = 0; i < identifier.length(); i++) {
    char ch = identifier.charAt(i);
    if (ch == quote) {
        retValue.append(quote);
    retValue.append(ch);
retValue.append(quote);
return retValue.toString();
StringquoteSqlIdentifier(String name)
quote Sql Identifier
return "`" + name + "`";
StringquoteSQLString(String s)
Converts input String into equivalent MySQL string
if (null == s) {
    return "NULL";
} else {
    return "'" + s.replace("'", "\\'") + "' ";