Two Laptop Bag*
The moose likes Other Application Frameworks and the fly likes Spring :Approach to call Stored Procedures Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring :Approach to call Stored Procedures" Watch "Spring :Approach to call Stored Procedures" New topic
Author

Spring :Approach to call Stored Procedures

Karthik Vijayarajan
Ranch Hand

Joined: Mar 13, 2005
Posts: 43
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


Karthik <br />SCJP 1.4 SCWCD 1.4 SCBCD 1.3
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6



Anyway, that's how we roll.


GenRocket - Experts at Building Test Data
Karthik Vijayarajan
Ranch Hand

Joined: Mar 13, 2005
Posts: 43
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Mar 13, 2005
Posts: 43
Thanks.
Cory Max
Ranch Hand

Joined: Jul 20, 2005
Posts: 83
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?


There are only 10 types of people in this world... Those who understand binary and those who don't.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jul 20, 2005
Posts: 83
Ahhh... inner classes. Makes perfect sense. Thanks for the reply Greg.
Gautam Trivedi
Greenhorn

Joined: Jun 10, 2006
Posts: 1
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.


Gautam Trivedi<br />Software Engineer
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Spring :Approach to call Stored Procedures
 
Similar Threads
Calling Stored Procedure from Hibernate mapping file
Calling Stored Procedure from jdbcTemplate
Question on JPA
java.sql.SQLException: ORA-03115: unsupported network datatype or representation
Spring JDBCTemplate _ MS SQL cursor