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:
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;
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:
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;
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.
The trouble seems to be the semi-colon at both the end of the long statement, and with the END; statement.
Your thoughts on the easiest way to do this?
I think I made some progress, but if the same SQL input file also has simpler SQL commands, like:
DROP TABLE TABLE.NAME_HERE;
They'll fail on my first condition here:
if ( !thisLine.startsWith("END;") && !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 { }
I check the statemendReady variable later on before I run the .execute.