Forums Register Login
Calling COBOL stored proc from Java Servlet
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;
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
catch(ClassNotFoundException ex){
System.out.println("Failed to locate database driver: "
+ ex.toString());
return iParm1;
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);
iParm1 = cstmt.getInt(1);
catch(SQLException ex) {
System.out.println("SQL exception occurred:" +
return iParm1;
return iParm1;
Could someone tell me if this is the right way to go about doing this?
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?
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.
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).
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 ]
We are using JRun to run our servlets. Thanks for your help.
Your mind is under my control .... your will is now mine .... read this tiny ad
Become a Java guru with IntelliJ IDEA

This thread has been viewed 2067 times.

All times above are in ranch (not your local) time.
The current ranch time is
Mar 20, 2019 11:10:51.