Announcement Announcement Module
No announcement yet.
setSql problem in stored procedure Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • setSql problem in stored procedure

    Hi all,

    I tried calling a stored procedure by setting the datasource and the sql in a method,but spring expects me to set the sql in the constructor itself.
    It says "SQL is required".

    Does that mean that for each stored procedure call I need to create a class?I have nearly 100 stored procedures in my project.

    Is there any workaround for that?

    Thanks in advance.

  • #2

    this forms will probably answer why setSQL is not working like you expect...


    • #3
      StoredProcedure objects are recommended if your procedure has at least one output parameter or returns multiple result sets. For those that don't you can use JdbcTemplate methods directly (StoredProcedure uses JdbcTemplate under the covers) to invoke the stored procedure.

      If you do have to create StoredProcedure classes, I would recommend doing them as embedded classes in the DAO to which they will be called. I found that stored procedures with the same result set can share RowMapper implementations. Also when the input is the same for multiple procedures, you can abstract that as well.

      Another solution is iBatis. Instead of specifying your result sets and input mappings in Java, you can do them in XML, naming them for reuse. I imagine the thought of replacing Java with XML doesn't appeal to you, but you should look at the features, like lazy loading and mapping to/from your Java objects.

      I think Hibernate has decent support for stored procedure, although I haven't really looked at their stored procedure support.