Source:
protected ArrayList<String> splitSqlQueries(String sql) { ArrayList<String> queries = new ArrayList<>(); StringBuilder query = new StringBuilder(); Character character; Boolean antiSlash = false; Boolean multiLineComment = false; Boolean singleLineComment = false; Boolean quoteString = false; Boolean doubleQuoteString = false; for (int item = 0; item < sql.length(); item++) { character = sql.charAt(item); if ((singleLineComment && (character.equals('\n') || item == sql.length() - 1)) || (multiLineComment && character.equals('/') && sql.charAt(item - 1) == '*')) { singleLineComment = false; multiLineComment = false; if (item == sql.length() - 1 && query.length() > 0) { queries.add(StringUtils.trim(query.toString())); } continue; } if (singleLineComment || multiLineComment) { continue; } if (character.equals('\\')) { antiSlash = true; } if (character.equals('\'')) { if (antiSlash) { antiSlash = false; } else if (quoteString) { quoteString = false; } else if (!doubleQuoteString) { quoteString = true; } } if (character.equals('"')) { if (antiSlash) { antiSlash = false; } else if (doubleQuoteString) { doubleQuoteString = false; } else if (!quoteString) { doubleQuoteString = true; } } if (!quoteString && !doubleQuoteString && !multiLineComment && !singleLineComment && sql.length() > item + 1) { if (character.equals('-') && sql.charAt(item + 1) == '-') { singleLineComment = true; continue; } if (character.equals('/') && sql.charAt(item + 1) == '*') { multiLineComment = true; continue; } } if (character.equals(';') && !antiSlash && !quoteString && !doubleQuoteString) { queries.add(StringUtils.trim(query.toString())); query = new StringBuilder(); } else if (item == sql.length() - 1) { query.append(character); queries.add(StringUtils.trim(query.toString())); } else { query.append(character); } } return queries; }

Target:
protected ArrayList<String> splitSqlQueries(String sql) { ArrayList<String> queries = new ArrayList<>(); StringBuilder query = new StringBuilder(); char character; Boolean antiSlash = false; Boolean multiLineComment = false; Boolean singleLineComment = false; Boolean quoteString = false; Boolean doubleQuoteString = false; for (int item = 0; item < sql.length(); item++) { character = sql.charAt(item); if ((singleLineComment && (character == '\n' || item == sql.length() - 1)) || (multiLineComment && character == '/' && sql.charAt(item - 1) == '*')) { singleLineComment = false; multiLineComment = false; if (item == sql.length() - 1 && query.length() > 0) { queries.add(StringUtils.trim(query.toString())); } continue; } if (singleLineComment || multiLineComment) { continue; } if (character == '\\') { antiSlash = true; } if (character == '\'') { if (antiSlash) { antiSlash = false; } else if (quoteString) { quoteString = false; } else if (!doubleQuoteString) { quoteString = true; } } if (character == '"') { if (antiSlash) { antiSlash = false; } else if (doubleQuoteString) { doubleQuoteString = false; } else if (!quoteString) { doubleQuoteString = true; } } if (!quoteString && !doubleQuoteString && !multiLineComment && !singleLineComment && sql.length() > item + 1) { if (character == '-' && sql.charAt(item + 1) == '-') { singleLineComment = true; continue; } if (character == '/' && sql.charAt(item + 1) == '*') { multiLineComment = true; continue; } } if (character == ';' && !antiSlash && !quoteString && !doubleQuoteString) { queries.add(StringUtils.trim(query.toString())); query = new StringBuilder(); } else if (item == sql.length() - 1) { query.append(character); queries.add(StringUtils.trim(query.toString())); } else { query.append(character); } } return queries; }