0
votes

Worklight Version 6.2

The adapters are deployed, and server is up.

I'm using the below code to invoke a SQL procedure:

 DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
ProcedureQName procedureQname = new ProcedureQName("EAttendanceSQLAdapter", "checkDomain");
String paramArray = "['"+userName+"']";
System.out.println("paramArray : "+ paramArray);
logger.info(">>>>>>>>>>>after procedureQname>>>>>>>>>>>>>>>>>>>>>");
InvocationResult result = service.invokeProcedure(procedureQname,paramArray);
com.ibm.json.java.JSONObject resultJsonObject = result.toJSON();

Its throwing me

java.lang.NullPointerException at this line " DataAccessService service = WorklightBundles.getInstance().getDataAccessService();"

Kindly advice. But the same set of code has worked for me in a different project.

Thanks

1
You are likely using a different java version? or perhaps the eclipse is not running/using the same JRE?Idan Adar
Hi Idan, we are using Java Version : 1.7 for both the projects.Reej
Provide the full log with the error.Idan Adar

1 Answers

0
votes

Something is not right IMO with the following line...
String paramArray = "['"+userName+"']";

Here's a working example:

import com.ibm.json.java.JSONObject;
import com.worklight.server.bundle.api.WorklightBundles;
import com.worklight.server.integration.api.DataAccessService;
import com.worklight.server.integration.api.InvocationResult;
import com.worklight.server.integration.api.ProcedureQName;

public void callProcedure() {
    DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
    String paramArray = "['param1', 'param2', 'param3']";
    ProcedureQName procedureQName = new ProcedureQName("adapterName",
"procedureName");
    InvocationResult result = service.invokeProcedure(procedureQName,paramArray);
    JSONObject jsonObject = result.toJSON();
    String value = (String)jsonObject.get("key");
}