Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a value from a sqlj stored procedure

Status
Not open for further replies.

bflash98

Programmer
Oct 10, 2003
1
US
I am trying to return a value from a stored procedured written in sqlj. I have been unable to find any documentation on how to accomplish this task. I am trying to use the count function and then pass that value to a variable that I want to return using the return statement.
Here is what I have so far. Any help is appreciated :).

/**
* SQLJ Stored Procedure DB2SA.RETURNORDERCOUNT
*/
import java.sql.*; // JDBC classes
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
#sql context SPContext;

#sql iterator RETURNORDERCOUNT_Cursor1 ( String );

public class RETURNORDERCOUNT
{
public static int rETURNORDERCOUNT ( String CustomerID,
ResultSet[] rs1 ) throws SQLException, Exception
{
RETURNORDERCOUNT_Cursor1 cursor1 = null;
SPContext ctx = null;
try
{ int x=0;
ctx = new SPContext( "jdbc:default:connection", false );
#sql [ctx] cursor1 =
{
SELECT Count(*) INTO :x

FROM DB2SA.CUSTOMERS AS CUSTOMERS

WHERE CUSTOMERS.CUSTOMERID = :CustomerID
};
rs1[0] = cursor1.getResultSet();
return x;
}
catch (SQLException e)
{

// Close open resources
try
{
if (cursor1 != null) cursor1.close();
if (ctx != null) ctx.close();
} catch (SQLException e2) { /* ignore */ };
throw e;
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top