Retreiving the results of a stored procedure call using Spring’s JdbcTemplate

Steve Neal Uncategorized Leave a Comment

A colleague asked me how to get to a result set generated by a stored procedure using Spring’s JdbcTemplate class. Understandably she’d been using the call() method to call the stored procedure but she was struggling to get to the values it returned.

It is possible to access the result set in exactly the same way as you would for a simple query. So rather than making a call like:;

just use the query method instead:

jdbcTemplate.query("exec myStoredProcedure", new RowCallbackHandler() {
    public void processRow(ResultSet rs) throws SQLException {
        long id = rs.getLong("id");
        String name = rs.getString("name");
        //work with id and name here...

This should work for any SQL that produces a ResultSet. We have been using Sybase (Adaptive Server Enterprise 15) – if you discover any incompatibilities with other databases, or know of any techniques, please leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *