Stored Procedure working in LS but not Java

I am trying to call a stored procedure and it works in LS and passes back all the output parameters. When I tried doing it by calling a Java agent it only returns the first 2 output parameters. The code for both methods is below. If someone has a minute to review this it is probably something simple that I am just not getting. The input parameters are the same (in LS I pull the same number off a profile doc that I have hard coded in Java until I get this piece working). Thank you.

LS code that works fine:

Sub Click(Source As Button)

'Domino connection variables

Dim session As New NotesSession

Dim db As NotesDatabase

Dim ws As New Notesuiworkspace

Dim uidoc As notesUIDocument 

Dim doc As NotesDocument

'AS/400 connection parameter variables

Dim pdoc As NotesDocument

Dim UserID As String

Dim Password As String

Dim AS400 As String

'DB2 connection objects

Dim DbConnection As ODBCConnection

Dim DbQuery As New ODBCQuery

Dim DbResultSet As New ODBCResultSet

'Stored procedure input parameters

Dim PORDER As String

Dim PDRIVER As String

Dim PTRACTOR As String

Dim PTRAILER As String

Dim PRECCOUNT As String

'Stored procedure output parameters

Dim PODFLAG As String

Dim PARM1 As String

Dim PARM2 As String

Dim PARM3 As String

Dim PARM4 As String

Dim PARM5 As String

'BEGIN MAIN PROGRAM

'Trap for errors

On Error Goto ErrorHandler

'Initialize Domino environment

Set uidoc = ws.CurrentDocument

Set db = session.CurrentDatabase

Set doc = session.DocumentContext()

Set pdoc = db.GetProfileDocument("ProfileDoc","")

'Set user ID, password and AS/400 system from profile document

UserID = pdoc.userID(0)

Password = pdoc.password(0)

AS400 = pdoc.AS400(0)

'Set customer number from current Domino document

PORDER = uidoc.FieldGetText("porder")

PDRIVER = uidoc.FieldGetText("pdriver")

PTRACTOR = uidoc.FieldGetText("ptractor")

PTRAILER = uidoc.FieldGetText("ptrailer")

PRECCOUNT = uidoc.FieldGetText("preccount")

'Connect to AS/400 database and set up result set object

Set DbConnection = New ODBCConnection

Sig=DbConnection.ConnectTo(AS400, UserID, Password)

Set DbQuery.Connection = DbConnection

Set DbResultSet.Query = DbQuery

'Execute stored procedure

Sig= DbResultSet.ExecProcedure("GTI.ICCSP" , PORDER, PDRIVER, PTRACTOR, PTRAILER, PRECCOUNT,_

PODFLAG, PARM1, PARM2, PARM3, PARM4, PARM5)	

'Fill in form fields from output

Call uidoc.FieldSetText("podflag", PODFLAG)

Call uidoc.FieldSetText("parm1", PARM1)

Call uidoc.FieldSetText("parm2", PARM2)

Call uidoc.FieldSetText("parm3", PARM3)

Call uidoc.FieldSetText("parm4", PARM4)

Call uidoc.FieldSetText("parm5", PARM5)	

'exit subroutine and finish program

DbResultSet.Close(DB_CLOSE)

DbConnection.Disconnect

Exit Sub

ErrorHandler:

Print "Error : " & Erl & ", " & Err & ", " & Error

End Sub

Java Agent that only prints the first 2 output parameters to the console:

import lotus.domino.*;

import java.sql.*;

public class JavaAgent extends AgentBase {

private static final String SERVER = "<name.domain.com>";

private static final String USER = "<user>";

private static final String WORD = "<password>";



public void NotesMain() {

	

	Session session = null;

	Connection conn = null;

	CallableStatement cs = null;





	try {

		session = getSession();

		AgentContext agentContext = session.getAgentContext();





		Database db = agentContext.getCurrentDatabase();

		Document doc = agentContext.getDocumentContext();



		Class.forName("com.ibm.as400.access.AS400JDBCDriver"); 

		conn = DriverManager.getConnection("jdbc:as400://" + JavaAgent.SERVER, JavaAgent.USER, JavaAgent.WORD);

		conn.setReadOnly(true);    // this is good for performance and a good idea if you're only reading

		

		cs = conn.prepareCall("{CALL GTI.ICCSP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");



		cs.setString (1, "3547659");

		cs.setString (2, "");

		cs.setString (3, "");

		cs.setString (4, "");

		cs.setString (5, "");

		cs.registerOutParameter (6, Types.VARCHAR);

		cs.registerOutParameter (7, Types.VARCHAR);

		cs.registerOutParameter (8, Types.VARCHAR);

		cs.registerOutParameter (9, Types.VARCHAR);

		cs.registerOutParameter (10, Types.VARCHAR);

		cs.registerOutParameter (11, Types.VARCHAR);

		cs.executeUpdate();		

		System.out.println(cs.getString(6));

		System.out.println("\n");

		System.out.println(cs.getString(7));

		System.out.println("\n");

		System.out.println(cs.getString(8));

		System.out.println("\n");

		System.out.println(cs.getString(9));

		System.out.println("\n");

		System.out.println(cs.getString(10));

		System.out.println("\n");

		System.out.println(cs.getString(11));

		System.out.println("\n");





		} catch (Throwable th) { 

			th.printStackTrace();

		} finally { 

			try { 

				if (cs != null) { 

					System.out.println("Callable Statement closed . . .");

					cs.close();

					cs = null;

				}



				if (conn != null) { 

					System.out.println("Connection closed . . .");

					conn.close();

					conn = null;

				}



				if (session != null) { 

					System.out.println("Session recycled . . .");

					session.recycle();

					session = null;

				}

		} catch (Throwable th) { 

			th.printStackTrace();

		}

	}		

	System.runFinalization();

	System.gc();

}

}

Subject: Stored Procedure working in LS but not Java

Can you share the procedure code?

-ck

Subject: RE: Stored Procedure working in LS but not Java

I don’t have access to the procedure code sorry, only the input and output parameters used.

Subject: Stored Procedure working in LS but not Java

Actually, it may not be needed. Couple things:

  1. Why use cs.executeUpdate() and not cs.execute(). I thought execute was more appropriate for stored procedures.

  2. Does the procedure return one or more result sets? For some reason I remember having to process the result sets before I grab the output parameters. No 100% sure though.

-CK

Subject: RE: Stored Procedure working in LS but not Java

I changed it to cs.execute() and the result is the same. I have assembled this code from samples and research so that is why I had executeUpdate. There is only one result set that is returned and I am starting to wonder if there is a problem printing all of it to the Java console too quickly or if its too much at one time. 4 of the 5 parameters are character strings that are 480 chars in length.

Subject: Stored Procedure working in LS but not Java

Sorry about the delay…

Without testing your code, I believe the Java issue is that you must register the out parameters before setting parameter values.

i.e.

cs = conn.prepareCall(“{CALL GTI.ICCSP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}”);

cs.registerOutParameter (6, Types.VARCHAR);

cs.registerOutParameter (7, Types.VARCHAR);

cs.registerOutParameter (8, Types.VARCHAR);

cs.registerOutParameter (9, Types.VARCHAR);

cs.registerOutParameter (10, Types.VARCHAR);

cs.registerOutParameter (11, Types.VARCHAR);

cs.setString (1, “3547659”);

cs.setString (2, “”);

cs.setString (3, “”);

cs.setString (4, “”);

cs.setString (5, “”);

cs.executeUpdate();

The decision for execute() -vs- executeUpdate() depends on whether the SP is updating or only reading data – but it looks like I have only used execute().

HTH.

-Doug.