Announcement

Collapse

Mirth Connect 4.1.0 Released!

Mirth Connect 4.1.0 is now available as an appliance update and on our GitHub page. Mirth Connect 4.1.0 includes new features such as new event log messages, additional fields to the Welcome to Mirth Connect screen, new information included in alerts as well as many smaller changes, updates, and improvements. This release also contains several improvements to commercial extensions. See the release notes for the list of fixes and updates.

Download | See What's New | Upgrade Guide | Release Notes

For discussion on this release, see this thread.
See more
See less

Help with prepared statement in javascript

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

  • Help with prepared statement in javascript

    Hi,
    I am trying to use a prepared statement with a DatabaseConnection object. I tried to use DatabaseConnection.executeUpdate(String sqlExpression, java.util.List params) API. When I try to pass in a javascript array like this:

    Code:
    var params = new Array();
    params[0] = $('lastName');
    params[1] = $('firstName');
    params[2] = $('middleName');
    
    var expression = "INSERT IGNORE INTO hl7_sample (patient_last_name, patient_first_name, patient_middle_initial) VALUES (?, ?, ?);"
    var result = dbConn.executeUpdate(expression, params);

    I get the exception:

    ERROR-406: JDBC Connector error
    ERROR MESSAGE: Error writing to database:
    org.mozilla.javascript.EvaluatorException: Cannot convert [email protected] to java.util.List (fff9cb5c-5920-499d-9383-eb395398ded0#22)
    at org.mozilla.javascript.DefaultErrorReporter.runtim eError(DefaultErrorReporter.java:95)
    at org.mozilla.javascript.Context.reportRuntimeError( Context.java:966)
    at org.mozilla.javascript.Context.reportRuntimeError( Context.java:1022)
    at org.mozilla.javascript.Context.reportRuntimeError2 (Context.java:992)


    I understand why that is happening but couldn't figure out the solution. Anybody knows the correct way to use this API? Thanks for your help.

    Post edited by: josemathews, at: 09/10/2007 12:17

  • #2
    Re:Help with prepared statement in javascript

    Googled around and found the solution. Since Rhino gives you access to the java classes I could use the following:

    Code:
    var params = new java.util.ArrayList();
    params.add($('lastName'));
    params.add($('firstName'));
    params.add($('middleName'));
    
    
    var expression = "INSERT IGNORE INTO hl7_test_sample (patient_last_name, patient_first_name, patient_middle_initial) VALUES (?, ?, ?);"
    var result = dbConn.executeUpdate(expression, params);

    Thanks,
    - jose

    Comment


    • #3
      Re:Help with prepared statement in javascript

      You might need to do:

      Code:
      var params = new Packages.java.util.ArrayList();
      Chris Lang

      Comment

      Working...
      X