Babu R
Babu R

Reputation: 1035

How to return MbElement[] from Java to ESQL?

I want to pass REFERENCE as a argument to Java method and transform it then i want to return in the form of MbElement[].

Till now I tried the following.

I am using the following code in ESQL

CALL retrieveData(CAST(AGE AS INTEGER),OutputRoot.XMLNSC.employees) into RESULT;

Calling java method as follows:

create function retrieveData(IN empId INTEGER,INOUT outputXML REFERENCE) 
returns integer 
language java 
external name "com.test.util.Database.retrieve";

Below is the java method:

public static Long retrieve(Long employeeAge,MbElement[] outputRoot) 
{ 
MbElement xmlnsc = outputRoot[0].getFirstElementByPath("XMLNSC"); 
MbElement employees =        xmlnsc.createElementAsFirstChild(MbElement.TYPE_NAME, "employees", null); 
MbElement employee =employees.createElementAsLastChild(MbElement.TYPE_NAME, "employee", ""); 
employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-id", 1001); 
employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-name", "john"); 
employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-age", 30); 
employee.createElementAsLastChild(MbElement.TYPE_NAME, "emp-city", "london"); 


return new Long(0); 
}

While testing the above code, it is throwing SqlRoutine::clearDownChildEnv error.

How to resolve this. Thanks in advance...

Upvotes: 0

Views: 1441

Answers (1)

Babu R
Babu R

Reputation: 1035

I got output.

I have used the following way:

DECLARE RESULT INTEGER;

SET OutputRoot.XMLNSC.employees=null;

DECLARE outputref REFERENCE TO OutputRoot.XMLNSC.employees;

CALL retrieveData(CAST(AGE AS INTEGER),outputref) into RESULT;

Its working fine.

Upvotes: 0

Related Questions