title: Extract SQL statements from Java/SQL files
body: <p>I have a huge codebase that has a lot of JAVA and .sql files. I intend to extract all the SQL statements from all these files.</p>
  
  <p>Here is the way I intend to achieve this - </p>
  
  <ol>
  <li>Build a regex file containing patterns like select, insert, delete, update etc that I intend to extract. </li>
  <li>Parse files line by line in code base and match against Regex. If match is found, register the code line, file name, pattern etc.</li>
  </ol>
  
  <p>The problem comes when the SQL queries are broken into multiple lines.</p>
  
  <p>I am using java.util.regex.Matcher and java.util.regex.Pattern methods to build/match regex patterns when I read lines using Buffered Reader. </p>
  
  <pre><code>  pattern = Pattern.compile(regexString,Pattern.CASE_INSENSITIVE);
    .
    .
    matcher = pattern.matcher(lineBuffer.readline().trim());
    if( matcher.find()){
      //Do something
    }
  </code></pre>
  
  <p>For Multiline statements, 
  I should look for the line terminator ";" - if not found, I can read next line and append the output in matched string so that it is understood as a single query.</p>
  
  <pre><code> while(!lineString.endsWith(";")) {
     lineString = lineString + lineBfr.readLine().trim();
   }
  </code></pre>
  
  <p>Is there a better way to achieve a solution to the requirement here using Pattern.MULTILINE or using StreamBuffers where I read the entire file into a single buffer and process further?</p>