3

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] 
  });
}
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
  • And what is the error you get in InsertDataFailed...? What is the "result"? Also, add the implementation of "procedure4". – Idan Adar Apr 22 '15 at 14:24
  • 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 Apr 22 '15 at 14:31
  • 1) obviously please edit the question with the code - not in comments. 2) I am asking what does it print in "result". – Idan Adar Apr 22 '15 at 14:34
  • Also change "result" to "result.errorMsg" in InsertDataFailed(). – Idan Adar Apr 22 '15 at 14:47
  • The result.errorMsg is returning null and If I give empty values in my form then it is returning success message – Vinod Kumar Marupu Apr 22 '15 at 14:54
  • @vinodh, can you provide the logs at server side. – dhineshsundar Apr 22 '15 at 14:55
  • @dhineshsundar Could you please let me know where could I found logs at server side in Mobile First Server .Thanks – Vinod Kumar Marupu Apr 22 '15 at 15:03
  • @vinodh, Select the _MobileFirst Development Server_ in Console View. – dhineshsundar Apr 22 '15 at 15:12
  • I tested the code end-to-end, and it works (checked in the database). The server logs are indeed required. You can find the messages.log file in \MobileFirstServerConfig\servers\worklight\logs\ (or as @dhineshsundar mentioned, in the MobileFirst Development Server view of the Console view in Eclipse. – Idan Adar Apr 22 '15 at 15:27
  • @IdanAdar00000651 SystemErr R 27276020 WorklightManagementPU-derby INFO [LargeThreadPool-thread-652] openjpa.Runtime - Though you are using optimistic transactions, OpenJPA is now beginning a datastore transaction because you have requested a lock on some data. – Vinod Kumar Marupu Apr 22 '15 at 17:01
  • Please upload to whole file somewhere, like Google Drive, Dropbox, etc. – Idan Adar Apr 22 '15 at 17:05
  • https://www.dropbox.com/s/r0t7nvlhqo2h4vo/DemoProject.rar?dl=0 – Vinod Kumar Marupu Apr 22 '15 at 17:27
  • Vinod... we asked for the full messages.log file from the location specified above. Not your project(!). – Idan Adar Apr 22 '15 at 17:34
  • https://www.dropbox.com/s/o8e0911z91azozf/messages.log?dl=0 – Vinod Kumar Marupu Apr 22 '15 at 17:54

1 Answers1

0

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.

Idan Adar
  • 44,156
  • 13
  • 50
  • 89