dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Intermediate
May 12, 2020

How to Call a Stored Procedure via the JdbcTemplate

Let's consider a stored procedure named FOO that return a List. We can call it via JdbcTemplate as follows:

@Service
public class FooService {

  private final JdbcTemplate jdbcTemplate;

  public FooService(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
  }

  public List callFOO() {
    SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(jdbcTemplate)
           .withProcedureName("FOO")
           .returningResultSet("FooResultSet",
                 BeanPropertyRowMapper.newInstance(FooDto.class));

    Map foos = simpleJdbcCall.execute(...);

    return (List) authors.get("FooResultSet");
  }
}
Octavia Anghel
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date