Execute Stored Procedure in Spring Jdbc

author-image   By Dhiraj,   04 February, 2017 15K

Spring jdbc provides very simple approach to execute stored procedures using SimpleJdbcCall.In this post we will be dicussing about how to execute stored proc in spring spring jdbc using SimpleJdbcCall.

Server Side

Follwing is a sample user class which will be persisted in the DB by calling a stored proc.

package com.devglan.model;

public class User {

    private int id;
    private String name;
    private String address;
    private String email;
    public int getId() {
	return id;

    public void setId(int id) {
	this.id = id;

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;

    public String getAddress() {
        return address;

    public void setAddress(String address) {
        this.address = address;

    public String getEmail() {
        return email;

    public void setEmail(String email) {
        this.email = email;

 Other Interesting Posts
Spring 5 Features and Enhancements
Insert Record in DB with Spring Boot JdbcTemplate
Insert Record in DB with Spring Boot Namedparameter Jdbctemplate
Fetch Auto Generated Primary Key Value After Insert Spring Jdbc
Working with Spring Boot Jdbctemplate
Working with Spring Boot NamedParameter Jdbctemplate
Spring Security Hibernate Example with complete JavaConfig
Securing REST API with Spring Security Basic Authentication
Websocket spring Boot Integration without STOMP with complete JavaConfig
Spring Boot Spring MVC Example
Spring Boot Thymeleaf Example
Spring Boot MVC with Jsp Example

Following is the class having an implementation to execute stored proc.Following method createUser() takes user object as a parameter and executes the stored proc create_user.

package com.devglan.dao.impl;

import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.stereotype.Repository;

import com.devglan.dao.UserDao;
import com.devglan.model.User;

public class UserDaoImpl implements UserDao {

    private SimpleJdbcCall createUserProc;
    public void setDataSource(DataSource dataSource) {
       this.createUserProc = new SimpleJdbcCall(dataSource).withProcedureName("create_user").withReturnValue();
    public User createUser(User user){
    	String userId = null;
    	SqlParameterSource inParams = new MapSqlParameterSource()
				.addValue("name", user.getName())
				.addValue("email", user.getEmail())
				.addValue("address", user.getAddress());
		Map result = createUserProc.execute(inParams);
		userId = (String) result.get("id");
		return user;


I hope this article served you that you were looking for. If you have anything that you want to add or share then please share it below in the comment section.

If You Appreciate This, You Can Consider:

  • Like us at: Facebook or follow us at Twitter
  • Share this article on social media or with your teammates.
  • We are thankful for your never ending support.

About The Author


I am an energetic professional who enjoys the challenges involved in working with people and resolving real-time problems. Technical expertise in building highly scalable, distributed and self-healing cloud applications. Technical Skills: Java/J2EE, Spring Framework, Hibernate, Angular, Reactive Programming, Microservices, Rest APIs, Kafka, ELK, etc.

Further Reading on Spring Jdbc

1 Insert Record In Db With Spring Boot Jdbctemplate

2 Insert Record In Db With Spring Boot Namedparameter Jdbctemplate

3 Fetch Auto Generated Primary Key Value After Insert Spring Jdbc

4 Working With Springboot Jdbctemplate

5 Working With Springboot Namedparameter Jdbctemplate