@Test public final void testEscapeSql() { Assert.assertEquals(null, StringUtil.escapeSql(null, true)); Assert.assertEquals("", StringUtil.escapeSql("", true)); Assert.assertEquals("90\\%", StringUtil.escapeSql("90%", true)); Assert.assertEquals("Phil''s", StringUtil.escapeSql("Phil's", true)); Assert.assertEquals("Phil''s\\\\\\\\Jay", StringUtil.escapeSql("Phil's\\Jay", true)); Assert.assertEquals("Phil''s\\\\Jay", StringUtil.escapeSql("Phil's\\Jay", false)); Assert.assertEquals("Phil\\_Jay", StringUtil.escapeSql("Phil_Jay", true)); Assert.assertEquals("Phil_Jay", StringUtil.escapeSql("Phil_Jay", false)); }
public static String escapeSql(String str, final boolean escapeForLike){ if (str == null) { return null; } else { str = StringUtil.replace(str, "'", "''"); if(escapeForLike) { str = StringUtil.replace(str, "\\", "\\\\\\\\"); str = StringUtil.replace(str, "%", "\\%"); str = StringUtil.replace(str, "_", "\\_"); } else { str = StringUtil.replace(str, "\\", "\\\\"); } } return str; }
StringUtil { public static String escapeSql(String str, final boolean escapeForLike){ if (str == null) { return null; } else { str = StringUtil.replace(str, "'", "''"); if(escapeForLike) { str = StringUtil.replace(str, "\\", "\\\\\\\\"); str = StringUtil.replace(str, "%", "\\%"); str = StringUtil.replace(str, "_", "\\_"); } else { str = StringUtil.replace(str, "\\", "\\\\"); } } return str; } }
StringUtil { public static String escapeSql(String str, final boolean escapeForLike){ if (str == null) { return null; } else { str = StringUtil.replace(str, "'", "''"); if(escapeForLike) { str = StringUtil.replace(str, "\\", "\\\\\\\\"); str = StringUtil.replace(str, "%", "\\%"); str = StringUtil.replace(str, "_", "\\_"); } else { str = StringUtil.replace(str, "\\", "\\\\"); } } return str; } private  StringUtil(); }
StringUtil { public static String escapeSql(String str, final boolean escapeForLike){ if (str == null) { return null; } else { str = StringUtil.replace(str, "'", "''"); if(escapeForLike) { str = StringUtil.replace(str, "\\", "\\\\\\\\"); str = StringUtil.replace(str, "%", "\\%"); str = StringUtil.replace(str, "_", "\\_"); } else { str = StringUtil.replace(str, "\\", "\\\\"); } } return str; } private  StringUtil(); static boolean isEmpty(final String obj); static boolean compareNullableStrings(final String str1,
			final String str2); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static String escapeSql(String str, final boolean escapeForLike); static byte[] convertHexToArray(final String s); static String toFixedString(final int value, final int length); static String removeHTMLTags(final String html); static int convertToInt(final String str, final int defValue); static long convertToLong(final String str, final long defValue); static double convertToDouble(final String str, final double defValue); static Float convertToFloat(final String str, final Float defValue); static String generateRandomString(final int length); @SuppressWarnings("restriction") static String getEncryptedPassword(final String clearTextPassword); @SuppressWarnings("restriction") static String encrypt(final String userId); @SuppressWarnings("restriction") static String decrypt(final String encryptKey); static List<String> parseCsvLine(final String csvLine); static List<String> parseCsvLine(final String csvLine, 
    									final char separator, final char quotechar, 
    									final char escape, final boolean strictQuotes); static final String explode(final char separator, final String[] input); static final String[] splitSafe(String word, String regex); }
StringUtil { public static String escapeSql(String str, final boolean escapeForLike){ if (str == null) { return null; } else { str = StringUtil.replace(str, "'", "''"); if(escapeForLike) { str = StringUtil.replace(str, "\\", "\\\\\\\\"); str = StringUtil.replace(str, "%", "\\%"); str = StringUtil.replace(str, "_", "\\_"); } else { str = StringUtil.replace(str, "\\", "\\\\"); } } return str; } private  StringUtil(); static boolean isEmpty(final String obj); static boolean compareNullableStrings(final String str1,
			final String str2); static String replace(final String text, final String searchString, final String replacement); static String replace(final String text, final String searchString, final String replacement, int max); static String escapeSql(String str, final boolean escapeForLike); static byte[] convertHexToArray(final String s); static String toFixedString(final int value, final int length); static String removeHTMLTags(final String html); static int convertToInt(final String str, final int defValue); static long convertToLong(final String str, final long defValue); static double convertToDouble(final String str, final double defValue); static Float convertToFloat(final String str, final Float defValue); static String generateRandomString(final int length); @SuppressWarnings("restriction") static String getEncryptedPassword(final String clearTextPassword); @SuppressWarnings("restriction") static String encrypt(final String userId); @SuppressWarnings("restriction") static String decrypt(final String encryptKey); static List<String> parseCsvLine(final String csvLine); static List<String> parseCsvLine(final String csvLine, 
    									final char separator, final char quotechar, 
    									final char escape, final boolean strictQuotes); static final String explode(final char separator, final String[] input); static final String[] splitSafe(String word, String regex);  }