Announcement

Collapse
No announcement yet.

Create Javascript Database Connection

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

  • Create Javascript Database Connection

    Hi everyone!

    I'm trying to create a Database Writer to do a couple of inserts, but it seems there is something wrong with the javascript (i must use javascript instead of SQL code directly)...

    Code:
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection('sun.jdbc.odbc.JdbcOdbcDriver','...','...','...');
    
    var req = $(IdReq);
    var result = dbConn.executeUpdate("INSERT IGNORE INTO MY_TABLE (FIELD) VALUES(" + req + "«»)"«»);
    
    dbConn.close();
    I can't even get a global variable, like 'Date'.
    Is this the correct way of doing that?

    Code:
    var dateTest = $(DATE);
    Thanks in advance...

  • #2
    Re:Create Javascript Database Connection

    This code is working for me :
    ===========================================
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('com.sybase.jdbc3.jdbc.SybDriver','jdbc:«»sybase: Tds:localhost:2638/hl7sample','dba','sql');

    //fill message header
    var expression = "INSERT IGNORE INTO HL7_HEADER ( separator,encoding,sending_app,sender) values ('"+ $('MSH_1') +"','"+ $('MSH_2') +"','"+ $('MSH_3') +"','"+$('MSH_4') + "')";
    var result = dbConn.executeUpdate(expression);

    //determine inserted header id
    var Query = "SELECT @@IDENTITY as ID FROM DUMMY";
    var qresult = dbConn.executeCachedQuery(Query);
    if (qresult.next() != '0')
    {
    // var header_id = qresult.getInt(1);
    var header_id = qresult.getInt(1).toString();
    qresult.close();
    }

    dbConn.close();
    [/code]
    ================================================== ===============
    all variables in insert are strings and calculated in transformer
    Hope this help

    Post edited by: VVV, at: 09/21/2007 09:34

    Post edited by: chrisl, at: 09/21/2007 14:52

    Comment


    • #3
      Re:Create Javascript Database Connection

      Everything looks fine in your code except that you don't have single quotes around your variable that you are inserting (if it is a string).
      Brendan Haverlock | Mirth Software Engineer | Mirth Corporation

      Comment

      Working...
      X