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;
}
}
}
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;
}
}
}