Announcement

Collapse
No announcement yet.

Syntax Question: INSERT variable to db

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

  • Syntax Question: INSERT variable to db

    I'm having trouble getting the syntax right for how to insert a variable into SQL Express 2005.

    I have tried:

    Code:
    var test1 = 3;
    
    query = dbConn.executeUpdate("INSERT IGNORE INTO someTable (someColumn) VALUES (test1);
    and

    Code:
    query = dbConn.executeUpdate("INSERT IGNORE INTO someTable (someColumn) VALUES ('test1');
    but neither work.

    By the way, it took me forever to figure out that you insert Destination Mappings like this:
    Code:
    query = dbConn.executeUpdate("INSERT IGNORE INTO someTable (someColumn) VALUES ('"+$('whatever')+"')");
    I hope that helps someone. Does anyone know of a good tutorial for JavaScript with JDBC? I haven't been able to find one. All of the JDBC tutorials I've found have given me information that doesn't work . . .

  • #2
    INSERT variable to db

    Hi DimitriA,
    I think you should create a store procedure in SQL server for inserting data in database.
    I wored with PostgreSQL and it didn't have any trouble.
    Ex: you create a store procedure with name and parameters as "sp_insert_to_db(character varying column1, numeric column2)"

    In Mirth:
    var column1 = $('data1');
    var column2 = $('data2');

    var sql = "SELECT * FROM sp_insert_to_db('" + column1 + "'," + column2 + ");";
    dbConn.executeUpdate(sql);

    I hope it's useful for you

    Huy

    Comment


    • #3
      Stored procedures are a pretty good idea (I have no idea why I don't use them...)

      Anyway, I think this will work for you Dimitri

      Code:
      query = dbConn.executeUpdate("INSERT IGNORE INTO someTable (someColumn) VALUES ('" + test1 + "');
      I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
      http://www.linkedin.com/pub/david-rothbauer/5/923/518
      codeismydrug.wordpress.com
      hl7coders.wordpress.com

      Test all my code suggestions prior to implementation

      Comment

      Working...
      X