in Oracle JDBC is it possible to batch stored procedure calls and retrieve OUT parameters?

Kirby picture Kirby · Jun 2, 2012 · Viewed 7.5k times · Source

I have a stored procedure in an Oracle 11g database like f(a IN, b IN, c OUT). I want to call it from JDBC in batch mode and then read all the OUT variables.
Is this possible? I have this so far

  CallableStatement statement = connection.prepareCall("f(?, ?, ?)");
  for(Item i : items) {
     int i = 0;
     statement.setString(++i, item.getA());
     statement.setString(++i, item.getB());
     statement.registerOutParameter(++i, Types.NUMERIC);
     statement.addBatch();
  }
  statement.executeBatch();
  int[] answers =  ?

Thanks

Answer

John Watts picture John Watts · Jun 2, 2012

Sadly, no.

The ability to make batch updates is the same for CallableStatement objects as it is for PreparedStatement objects. In fact, a CallableStatement object is restricted to the same functionality that a PreparedStatement object has. More precisely, when using the batch update facility, a CallableStatement object can call only stored procedures that take input parameters or no parameters at all.

Reference: http://docs.oracle.com/javase/1.4.2/docs/guide/jdbc/getstart/callablestatement.html#1000220