Java String Tokenize tokenizeStatement(String statement)

Here you can find the source of tokenizeStatement(String statement)

Description

Given an SQL statement containing "?"

License

Open Source License

Parameter

Parameter Description
statement The query

Return

The tokenized query

Declaration

public static String tokenizeStatement(String statement) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w  ww. java  2s  .  c  o m*/
     * Given an SQL statement containing "?" placeholders, this function replaces question marks
     * with a placeholder of type "{POS}" where "POS" is the position of the question mark starting
     * from 0. I.e. the first question mark will be replaced with "{0}", the second with "{1}", etc.
     * NOTICE: this method does NOT work if question marks are used as literals in the query.
     * @param statement The query
     * @return The tokenized query
     */
    public static String tokenizeStatement(String statement) {
        String modifiedSql = statement;
        int variableCount = 0;
        while (modifiedSql.contains("?")) {
            modifiedSql = modifiedSql.replaceFirst("\\?", "{"
                    + variableCount + "}");
            variableCount++;
        }
        return modifiedSql;
    }
}

Related

  1. tokenizePath(String path)
  2. tokenizePathAsArray(String path)
  3. tokenizePattern(String pattern)
  4. tokenizeQuotedStrings(final String aInput, final String aDelimiters)
  5. tokenizeQuotes(String f1)
  6. tokenizeString(final String inputString, final String seperator)
  7. tokenizeString(String inString, char delimiter, String enclosures)
  8. tokenizeStringArray(String[] array, String token)
  9. tokenizeStringWithQuotes(String line, String quoteStyle)