web stats
Syntax Question: INSERT variable to db - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 07-28-2011, 02:55 PM
DimitriA DimitriA is offline
Mirth Newb
 
Join Date: Jul 2011
Posts: 17
DimitriA is on a distinguished road
Default 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 INTO someTable (someColumn) VALUES (test1);
and

Code:
query = dbConn.executeUpdate("INSERT 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 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 . . .
Reply With Quote
  #2  
Old 07-28-2011, 07:27 PM
doanhuy doanhuy is offline
Mirth Newb
 
Join Date: Mar 2011
Location: HoChiMinh, VietNam
Posts: 18
doanhuy is on a distinguished road
Default 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
Reply With Quote
  #3  
Old 07-29-2011, 04:59 AM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

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 INTO someTable (someColumn) VALUES ('" + test1 + "');
Reply With Quote
Reply

Tags
javascript, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 03:31 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation