Executing PL/SQL from ANT - how to get the output
Javaddicts and the Amis blog are reporting about executing pl/sql statements from Ant: Executing Oracle PL/SQL from Ant, Executing PL/SQL from ANT – how to keep the format straight.
I’ve also written an Ant target for my current project where we execute pl/sql. The pl/sql queries domain values from some tables and outputs an xml document containing these domains. The problem with Ant’s sql task is that it doesn’t display the output created using dbms_output. So i’ve extended the SQLExec class, to copy all the output created using dbms_output to standard out. This is done in the printDbmsOutputResults method:
/**
- Print dbms_output results
*/
String getLineSql = “begin dbms_output.get_line(?,?); end;”;
CallableStatement stmt = conn.prepareCall(getLineSql);
boolean hasMore = true;
stmt.registerOutParameter(1, Types.VARCHAR);
stmt.registerOutParameter(2, Types.INTEGER); while (hasMore) {
boolean status = stmt.execute();
hasMore = (stmt.getInt(2) == 0); if (hasMore) {
out.println(stmt.getString(1));
}
}
stmt.close();
}