3
votes

I'm trying to insert data to a database using a SQL Adapter in IBM mobilefirst platform, however my code reaches the failure function...

main.js:

function insertData(){

  alert("Function InsertData called");
  var fname = document.forms["form1"]["fname"].value.toString();
  var lname = document.forms["form1"]["lname"].value.toString();
  var email = document.forms["form1"]["email"].value.toString();
  var pwd = document.forms["form1"]["pwd"].value.toString();
  // alert("fname"+fname);

  var invocationData = {
    adapter: 'SQLDemo',
    procedure: 'procedure4',
    parameters:[fname,lname,email,pwd]
  };

  var options = {
    onSuccess : InsertDataSuccess,
    onFailure : InsertDataFailed,
    timeout : 30000
  };
  WL.Client.invokeProcedure(invocationData, options);
}

function InsertDataSuccess(result){
  alert("Success");
  WL.Logger.debug("Retrieve success" +  JSON.stringify(result));
}

function InsertDataFailed(result){
  alert("Failure");
  WL.Logger.debug("Retrieve success" +  JSON.stringify(result));
}

Adapter'sSQLDemo-impl.js:

var procedure4Statement = WL.Server.createSQLStatement("INSERT INTO INNOVATION (FIRSTNAME,LASTNAME,EMAIL,PASSWORD) VALUES(?,?,?,?)");
function procedure4(fname,lname,email,password) {
  return WL.Server.invokeSQLStatement({
      preparedStatement : procedure4Statement, 
      parameters : [fname,lname,email,password] 
  });
}
1
And what is the error you get in InsertDataFailed...? What is the "result"? Also, add the implementation of "procedure4".Idan Adar
It is going to onFailure function var procedure4Statement = WL.Server.createSQLStatement("INSERT INTO INNOVATION (FIRSTNAME,LASTNAME,EMAIL,PASSWORD) VALUES(?,?,?,?)"); //var procedure3Statement = WL.Server.createSQLStatement("select * from INNOVATION where FIRSTNAME=? and id=?"); function procedure4(fname,lname,email,password) { return WL.Server.invokeSQLStatement({ preparedStatement : procedure4Statement, parameters : [fname,lname,email,password] }); }Vinod Kumar Marupu
1) obviously please edit the question with the code - not in comments. 2) I am asking what does it print in "result".Idan Adar
Also change "result" to "result.errorMsg" in InsertDataFailed().Idan Adar
The result.errorMsg is returning null and If I give empty values in my form then it is returning success messageVinod Kumar Marupu

1 Answers

0
votes

From the messages.log file:

E FWLSE0099E: An error occurred while invoking procedure [project DemoProject]SQLDemo/SqlStatementFWLSE0100E: parameters: [project DemoProject] DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=from;AJAX set FIRSTNAME=?;.., DRIVER=3.61.75. Performed query: update AJAX set FIRSTNAME=? from AJAX where id=? FWLSE0101E: Caused by: [project DemoProject]com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=from;AJAX set FIRSTNAME=?;.., DRIVER=3.61.75java.lang.RuntimeException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=from;AJAX set FIRSTNAME=?;.., DRIVER=3.61.75.

...

Invalid data conversion: Parameter instance vinod is invalid for the requested conversion. ERRORCODE=-4461, SQLSTATE=42815

And there are more exceptions below it.

Make sure in your database scheme that you're actually expecting strings, not limiting value length too much, etc.