Announcement Announcement Module
No announcement yet.
Spring 3 Dao - Calling Stored Procedure Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3 Dao - Calling Stored Procedure


    I am new to Spring mvc 3. Just a toddler.
    I would like to have pointers on how to call a stored procedure in Spring MVC 3.
    Examples would be really appreciated.
    Please forgive my ignorance.

  • #2
    Well you wouldn't want to call a backend database stored procedure from Spring MVC.

    I'll explain. Spring MVC is the module of Spring Framework for building Web application layer. Meaning the layer that is only responsible for receive an HttpRequest getting the info out of the request, then delegating to other layers to do the work. So typically calling down to a Service/business logic layer, which then calls down to the DAO layer. The service and DAO layer can exist in any type of application using the SpringFramework and not even use or touch Spring MVC.

    So I think your first confusion is that Spring MVC is the Spring Framework instead a module of the Spring Framework.

    Now, to have a Repository/DAO call a Stored Procedure that is more a likely question.

    In Spring there is a class called StoredProcedure that you extend and set up the IN/OUT parameters in the constructor and then overwrite a method execute to execute the stored procedure.

    Here's an example I found online

    class ActStartled extends StoredProcedure {
      private static final String SQL = "p_proc";
      ActStartled(DataSource dataSource) {
          super(dataSource, SQL);
          declareParameter(new SqlParameter("n", Types.INTEGER));
      void execute(int value) {
          Map<String, Object> parameters = new HashMap<String, Object>(1);
          parameters.put("n", value);
    Now that I showed how to do it. I will also recommend, that unless this is a stored procedure that has existed for a really long time and you are forced to use it. Do not use stored procedures in your application as you will be tying logic into the database, which tends to be too much coupling and locks you into that database vendor.

    Good Luck



    • #3
      Thank you Mark.
      It helped. Now I have a better understanding.