wood burning stoves 2.0*
The moose likes Spring and the fly likes Calling stored procedures from a generic Class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Calling stored procedures from a generic Class." Watch "Calling stored procedures from a generic Class." New topic
Author

Calling stored procedures from a generic Class.

santosh malreddy
Greenhorn

Joined: Jan 09, 2013
Posts: 12

Hi ,

I am a new biew to Spring.. I have a bunch of stored procedures around 30-40 in number. (This is just a simple proc call from java to a Stored procedure)

And my requirement is to call these bunch of Stored Procs from a Generic class which I have to create using SPring or Spring and Hibernate.. Can you guys please help me.. I am not able to figure out how to do this.. I am really in a serious issue with this problem..Can you please send me the example code and also of how to start developing and from where to start...
Your help is highly appreciated

Thanks
Olive
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

All I can recommend is reading what is in the Spring Framework documentation under Jdbc and Stored Procedure.

Basically in Spring Jdbc you can write a class that extends StoredProcedure. In the constructor you tell it what are the In and Out parameters. In the execute method you override you set those IN parameters and OUT parameters.

I have no example code except what you would find in the documentation.

Good Luck

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
santosh malreddy
Greenhorn

Joined: Jan 09, 2013
Posts: 12

Hi Mark.

Thanks alot for the prompt reply.. I am able to comeup with a part of the code extending Stored Procedures , but my question here is how am I able to pass the parameters and how am I able to pull the stored procedures is my question..??? I am not sure what else need to added or whats the issue with the code or if I am missing something in the code and wt other classes I need to develop.. Can you please help me to sort out this issue.

Please find the code snippet below..

Thanks Once again for your help,

**************************************************************

public class CallGenericStoredProc extends StoredProcedure {
private static final Log log = LogFactory.getLog(CallGenericStoredProc .class);

private static final String STORED_PROC_NAME = "PROC_NAME";

public CallGenericStoredProc (DataSource ds) {
super(ds, STORED_PROC_NAME);

declareParameter(new SqlParameter("params", Types.VARCHAR));
compile();
}

public String execute(String params) {
Map inParams = new HashMap();
inParams.put("params", params);

Map outParams = execute(inParams);
if (outParams.size() > 0) {
return outParams.get("params").toString();
} else {
return null;
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17258
    
    6

First, we have CODE tags that help keep posted code formatted with indentation so it is easier to read.

1) I thought in the constructor when you add a parameter you have to tell it whether it is an IN or OUT parameter, but I could be wrong. I haven't ever used StoredProcedure class because I avoid having any stored procedures anywhere in any application.

As far as now using it, I think you would have code in your DAO that uses it. Maybe with JdbcTemplate?

Again, I recommend going to the Spring Framework documentation and look at their example there.

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Calling stored procedures from a generic Class.