• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring :Approach to call Stored Procedures

 
Karthik Vijayarajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to find out the options we have with Spring for invoking stored procedures. So far, i have found out two options.

1.jdbcTemplate.update(" call STORED_PROC(?,?,?) ",paramsArray);

2.Extend the StoredProcedure class.

While i prefer to use the first option(for simplicity), i am not able to get output parameters with jdbcTemplate. Can i specify only input parameters with jdbcTemplate?

Also, if you have come across other ways of invoking stored procs, please share the same.

Thanks
Karthik
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Anyway, that's how we roll.
 
Karthik Vijayarajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg.
I tried extending StoredProcedure and it works great.
Can i not specify OUT parameters in JdbcTemplate.update() method. I did look at the documentation but it is not very precise.

Thanks
Karthik
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by karthik vijayarajan:
Can i not specify OUT parameters in JdbcTemplate.update() method.


No, I don't believe so. That's why they have the StoredProcedure class.
 
Karthik Vijayarajan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Cory Max
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger: It seems as if your classes are private. How exactly does this work? Is that a type-o or am I missing something?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Cory Max:
Gregg Bolinger: It seems as if your classes are private. How exactly does this work? Is that a type-o or am I missing something?


Those are only the stored procedure classes which happen to be inner classes of a public DAO class. DAO methods such as:

public List<Sport> getSports();

actually use the StoredProcedure class. I could have made them anonymous inner classes to the getSports method but that gets nasty and there are more than the one method that might use a specific stored procedure class. But since they are confined to usage within the single DAO (no other DAO needs to GetSports other than the SportDAO) they are private inner classes.

That said, making them each their own public class outside of the DAO class is perfectly valid as well. Its just preference.
 
Cory Max
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh... inner classes. Makes perfect sense. Thanks for the reply Greg.
 
Gautam Trivedi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik Vijayarajan wrote:Thanks Greg.
I tried extending StoredProcedure and it works great.
Can i not specify OUT parameters in JdbcTemplate.update() method. I did look at the documentation but it is not very precise.

Thanks
Karthik


use jdbcTemplate().call(....) method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic