title: What's the easiest way to parse multi-line SQL statements in Java?
body: <p>I'm pretty new to Java, but I'm looking for Java code that can take multi-line SQL statements, say something like this from a flat file:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER REQ.TR_INPT_STAY_DETAI_SQ_BI
    BEFORE INSERT ON REQ.INPT_STAY_DETAIL
    FOR EACH ROW
  BEGIN
    SELECT REQ.SQ_INPT_DETAIL.nextval INTO :new.INPT_STAY_DETAIL_PID from DUAL;
  END;
  </code></pre>
  
  <p>And convert those multi-line statements into one line SQL statements like this (maybe wrapped in this display), to be executed as a single JDBC statement against an Oracle database:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER REQ.TR_INPT_STAY_DETAI_SQ_BI BEFORE INSERT ON REQ.INPT_STAY_DETAIL FOR EACH ROW BEGIN SELECT REQ.SQ_INPT_DETAIL.nextval INTO :new.INPT_STAY_DETAIL_PID from DUAL; END;
  </code></pre>
  
  <p>I've tried to do this with multiple BufferedReaders, and/or using the mark() method, but I can't seem to get it to work.</p>
  
  <p>The trouble seems to be the semi-colon at both the end of the long statement, and with the END; statement.</p>
  
  <p>Your thoughts on the easiest way to do this?</p>
  
  <hr>
  
  <p>I think I made some progress, but if the same SQL input file also has simpler SQL commands, like:</p>
  
  <pre><code>DROP TABLE TABLE.NAME_HERE;
  </code></pre>
  
  <p>They'll fail on my first condition here:</p>
  
  <pre><code>if ( !thisLine.startsWith("END;") &amp;&amp; !thisLine.equals("/") ) {
      sqlBuf.append(thisLine).append(" ");
      statementReady = false;
  }
  else if (thisLine.startsWith("END;")) {
      sqlBuf.append(thisLine).append(" ");
      statementReady = true;
  }
  else if (thisLine.equals("/")) {
      statementReady = true;
  }
  else { }
  </code></pre>
  
  <p>I check the statemendReady variable later on before I run the .execute.</p>