The ultimate problem is that currently Jaybird makes no clear distinction between OUT
parameters (which Firebird technically doesn't have), the (single row) return values of an executable procedure, and the (multiple row) result set of a selectable stored procedure. The problem you are experiencing is (at least partially) related to JDBC-229 (and a general review of the CallableStatement
implementation that is planned for Jaybird 3.0).
This leads to a situation where the result set backing the single row is read twice, once as a ResultSet
and once through the getters on CallableStatement
, however as the backing result set has been closed, this causes a NullPointerException
when the OUT
parameter is retrieved.
There are two potential workarounds:
Disable results processing on the
JdbcTemplate
:JdbcTemplate jdbcTemplate = new JdbcTemplate(ds); jdbcTemplate.setSkipResultsProcessing(true);
Do not declare the
OUT
parameter, and process the result set that is returned in theout
map (which contains aList
with aMap
for the result set):last_inserted = (int) ((List<Map>) out.get("#result-set-1")).get(0).get("NEWID");
Note that the cast from Object
to int
assumes Java 7 or higher.
I have reported this specific problem as JDBC-350 and I will try to fix this in the next Jaybird release (2.2.6).