• 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

how to call Stored Procedures, and get parameters from a web page

 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working on a web site, where i am listing a set of stored
procedures on a page. user can click any of them, then it prompts another page where it asks for parameters for the stored
procedure. After entering the parameters for the Stored Procedure
user can submit the form on that page, it should call another
servlet.
where i need to execute stored procedure in a httpServlet. The parameters for the Stored PRocedure will come from the previous
servlet along with the Stored Procedure name. Different stored
procedures have different parameters, user can click
Spexecute?procedure_name=SP_EXPORT_PGE&Invoice_number=ewrew&+user_id=wrw
MY QUESTION IS HOW DO I COLLECT THESE VALUES(sometimes it can have three or four or five parameters)
and then call Stored PRocedure in the database, i know how to
connect to the database, but don't know how to call stored procedure.
does anyone has any code that solved similar problem,
sorry i think i am not very clear, ask me if this doesn't make sense
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stored Procedures are executed using CallableStatement in JDBC. So here are the steps to follow to write a generic method for executing any procedure:
1. get connection
2. get the string array of the parameters for the procedure and put them in a single string delimited by comma(,)
3. create a handle to SallableStatement like this:
CallableStatement s =
connection.prepareCall("{call " + pocedureName + "(" + listOfParamters + ")}");
4. execute the statement.
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting parameters from the other web page like this.
I need to call the Stored Procedure. How do i construct the STring array of parameters, if i construct it inside while or
if clause, i can't call it outside the while clause.
how do i go about this.
while (enum.hasMoreElements()) {
String name = (String) enum.nextElement();
String values[] = req.getParameterValues(name);

if (values != null) {
for (int i=0; i<values.length; i++) {
out.println(i + " " + name + " = " + values[i] + "<BR>" );
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic