• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling stored procedures from a generic Class.

 
Greenhorn
Posts: 12
Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
santosh malreddy
Greenhorn
Posts: 12
Hibernate Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic