Announcement

Collapse
No announcement yet.

Database Writer - use javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Database Writer - use javascript

    Trying to insert into a database using the javascript option. This is the script:

    var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('com.mysql.jdbc.Driver','jdbc:mysq l://localhost:3306/MYTABLE','myuser','mypassword& #039;
    var var1 = ${idpatient};
    var var2 = ${class};
    var var3 = ${referringLname};
    var var4 = ${idpatient};
    var expression = "INSERT IGNORE INTO REGISTRATIONS (`IDPATIENT`,`PATIENT_CLASS`, `REFERRING_DOCTOR`,`VISIT_NUMBER`) VALUES (`" + var1 + "`,`" + var2 + "`,`" + var3+ "`,`" + var4 + "`)";
    var result = dbConn.executeUpdate(expression);
    dbConn.close();

    I get the following exception: (I don't think it likes using the mapped variables ${idpatient} etc....)

    Caused by: org.mule.umo.lifecycle.InitialisationException: Initialisation Failure: missing ; before statement (4e4514d1-d1c3-4933-b232-d4bb063cb60b#3)
    at org.apache.commons.digester.Digester.createSAXExce ption(Digester.java:2919)
    at org.apache.commons.digester.Digester.createSAXExce ption(Digester.java:2945)
    at org.apache.commons.digester.Digester.endElement(Di gester.java:1133)
    at org.apache.xerces.parsers.AbstractSAXParser.endEle ment(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanEndElement(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerI mpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse( Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser .parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digeste r.java:1685)
    at org.mule.config.builders.AbstractDigesterConfigura tion.process(AbstractDigesterConfiguration.java:11 9)
    ... 5 more

    Can anyone help!!!!


  • #2
    Re: Database Writer - use javascript


    You might try delimiting your single quotes:

    var var1 = ${idpatient};
    var var2 = ${class};
    var var3 = ${referringLname};
    var var4 = ${idpatient};
    var expression = "INSERT IGNORE INTO REGISTRATIONS (\`IDPATIENT\`,\`PATIENT_CLASS\`, \`REFERRING_DOCTOR\`,\`VISIT_NUMBER\`) VALUES (\`" + var1 + "\`,\`" + var2 + "\`,\`" + var3+ "\`,\`" + var4 + "\`)";


    Comment


    • #3
      Re: Database Writer - use javascript

      Thanks for the input.
      Seems to be that the problem was partially related to incorrect quotes but also the syntax to use for mapped variables in javascript i.e. $('idpatient&#039 works, while ${idpatient} does not. The following works o.k.

      var expression = "INSERT IGNORE INTO REGISTRATIONS (IDPATIENT,PATIENT_CLASS,REFERRING_DOCTOR,VISIT_NU MBER) VALUES ('"+ $('idpatient&#039 + "','" + $('class&#039 + "','" + $('referringLname&#039 + "','" + $('visitNumber&#039 + "&#039";

      Comment

      Working...
      X