Here you can find the source of quoteIfNotNull(String str)
public static String quoteIfNotNull(String str)
//package com.java2s; // in accordance with the terms of the license agreement accompanying it. public class Main { public static String quoteIfNotNull(String str) { return str = (str != null) ? str = "'" + escapeApostrophe(str) + "'" : null; }// w w w .j av a 2s.com public static String escapeApostrophe(String str) { if (str.indexOf("'") > -1) { return substitute(str, "'", "''"); } return str; } /** * Simple string replace routine, return the same string with * all instances of from replaced with to **/ public static String substitute(String str, String from, String to) { if (from == null || from.equals("") || to == null) return str; int index = str.indexOf(from); if (index == -1) return str; StringBuffer buf = new StringBuffer(str.length()); int lastIndex = 0; while (index != -1) { buf.append(str.substring(lastIndex, index)); buf.append(to); lastIndex = index + from.length(); index = str.indexOf(from, lastIndex); } // add in last chunk buf.append(str.substring(lastIndex)); return buf.toString(); } }