I know for more than one result, you don't have much choice for using out parameters, but I'm wondering whats the difference between the following 2 cases where there's one out parameter.
Say I have two stored procedures:
CREATE PROCEDURE no_out_params(IN foo INT)
BEGIN
SELECT foo + 1 as result;
END
and
CREATE PROCDURE with_out_params(IN foo INT, OUT result INT)
BEGIN
SET result = foo + 1;
END
Then using JDBC I can either:
CallableStatement c1 = conn.prepareCall("{ call no_out_params(?)}");
c1.setInt(1, 5);
ResultSet rs = c1.executeQuery();
if (rs.next()) {
return rs.getInt("result"); // or rs.getInt(1)
}
or
CallableStatement c1 = conn.prepareCall("{ call with_out_params(?, ?)}");
c1.setInt(1, 5);
c1.registerOutParameter(2, Types.INT);
c1.executeQuery();
return c1.getInt(2);
Assuming you're properly closing everything in try/finally's (omitted for brevity), does the non-out parameter method provide any advantage? If not, is it reasonable to assume that one should always use out parameters (if only to to be consistent in cases where there's more than one result)?