• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 553
  • Last Modified:

Calling stored procedures spring DAO

I was reading folowing lines and I did not understand clearly.

Calling stored procedures
Sometimes we choose to execute our persistence operations as stored procedures
in the database rather than SQL in our application. This may be due to performance
reasons, company policy, or just a matter of taste.
Spring provides the same support for calling stored procedures as it does for executing
statements and queries. This time get the support by implementing

what it means by
>> persistence operations as stored procedures
in the database rather than SQL in our application

are the stored procedures are not SQL.

Any ideas, resources,sample code,links, highly appreciated. thanks in advance.
2 Solutions
It means instead of your persistence layer generating dynamic SQL (insert, update, delete statements) for its persistent operations, it can make use of pre-created stored procedures for this. Some organizations do not allow dynamic SQL, but force developers to write everything "pre-compiled" as stored procedures in the database.
The stored procedures are SQL, for course, but it think that when it says "persistence operations as stored procedures in the database rather than SQL in our application" it means SQL written directly on the source code.

You can do it both ways, and it will work in any of this ways. Example:

1 - you can write a stored procedure called listPeople with the content: "select code, name from table_people" and call it, with something like "execute listPeople" from inside your source code

2 - Inside your code, you can declare a string  with the content "select code, name from table_people" and execute this sql.

Both are SQL, but people sometimes like one rather than the other.

Some of the reasons that some people prefer option number 1, Stored Procedures, are:
- Its precompiled, like mrjoltcola said
- You can give permissions directly no the procedure object, making it safer.
- If you have a complex sql string, it will run faster, giving you better performance.

Some of the reasons people prefer option number 2, sql directly on the code, are:
- It's simpler
- You don't need a DBA permission everytime you have to change a query

If you have any more questions, feel free to ask.

If this answer helped you, please mark it as helpful on the button on the side.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now