dcsimg
 

Submitted by: Octavia Anghel(octaviaanghel@gmail.com)

Tuesday May 12th 2020 by Octavia Anghel

Language: Java, Expertise: Intermediate - See an example of 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");
  }
}
Home
Mobile Site | Full Site