• 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 COBOL stored proc from Java Servlet

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to call a COBOL stored proc from a Java Servlet. The stored proc is stored on a DB2 database. I need to send 6 inputs to the COBOL stored proc and the output will be the return code of the stored proc. I'm not sure if I'm going about this the right way. This is how my code looks...
public int callStoredProc(CallableStatement cstmt,
Connection con,
String sYear,
String sReportNbr,
String sSystemCode,
String sUserId,
String sModuleNbr,
String sFormId){
int iParm1 = 0;
try{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.out.println("Failed to locate database driver: "
+ ex.toString());
return iParm1;
}
try{
cstmt = con.prepareCall("{? = CALL MKTPZ90C
(?, ?, ?, ?, ?, ?)}");
cstmt.registerOutParameter(1, Types.INTEGER);
cstmt.setString(2, sYear);
cstmt.setString(3, sReportNbr);
cstmt.setString(4, sSystemCode);
cstmt.setString(5, sUserId);
cstmt.setString(6, sModuleNbr);
cstmt.setString(7, sFormId);
cstmt.execute();
iParm1 = cstmt.getInt(1);
CloseSQLStatement(cstmt);
}
catch(SQLException ex) {
CloseSQLStatement(cstmt);
System.out.println("SQL exception occurred:" +
ex.toString());
return iParm1;
}
return iParm1;
}
Could someone tell me if this is the right way to go about doing this?
Thanks!!!
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks about right -- now I have two questions:
(1) Why are you using the ODBC bridge rather than the native DB2 JDBC drivers (which are WAY faster)
(2) Have you tested this? If so, did you get any errors?
Kyle
 
Donna Reschke
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post a code example of using the native DB2 JDBC drivers? If I already have a connection established in my servlet, and I pass the con variable to my method, wouldn't this work just as well? I have not yet tested this, I'll be doing that tomorrow. First I want to test the stored procedure to make sure it is running smoothly.
Thanks for your input.
 
Kyle Brown
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, one more question and then I'll post code, I promise
Are you running this in WebSphere or Tomcat, or some other Servlet engine?
(Really, there's a reason for this question -- I have to know how to tell you how to best obtain the connection for the DB2 driver).
Kyle
One more thing -- the "Class.forName()" business only needs to happen ONCE in your entire program -- if you're being passed a connection you probably already have done this, so you don't need it.
[ February 11, 2002: Message edited by: Kyle Brown ]
 
Donna Reschke
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using JRun to run our servlets. Thanks for your help.
Donna
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic