?
Solved

javascript question for inserting record in sql server

Posted on 2010-11-16
4
Medium Priority
?
591 Views
Last Modified: 2012-05-10
I'm trying to use this code and I get an error  saying:

Error in connector "Database Writer" at Javascript:
Error on line 5: missing ; before statement


It is hard to tell here but line 5 is where I assign the var sql= statement.

the variables ${FirstName} are predifined variables in the MirthConnect application. Just know that they contain the info needed.



var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://localhost:1433/Demographics','MirthUser','b9isnice');

if (MsgType == 'ADTA08')
{
  var sql="INSERT INTO Patient (PatientID,FirstName,MiddleName,LastName,Gender,SSN,HomePhone,HomeAddress1,City,State,Zip) values("+${PatientID}+",'"+${FirstName}+"','"+${MiddleName}+"','"+${LastName}+"','"+${Sex}+"','"+${myssn}+"','"+${HomePhone}+"','"+${Address1}+"','"+${City}+"','"+${State}+"','"+${Zip}+"')";

logger.error("Query is: " + sql);



var status=dbConn.executeUpdate(sql);



}


dbConn.close();

Open in new window

0
Comment
Question by:rutledgj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Expert Comment

by:celazkon
ID: 34146508
Try to use simple quotes instead of double quotes.
I don't program in Javascript now for some time, but from what I remember, this has been always an issue

Hope it helps, good luck
0
 
LVL 16

Accepted Solution

by:
jmatix earned 2000 total points
ID: 34146635
Braces - {} are not valid in a javascript variable name. So if the code above is javascript then those variables need to be changed. Are you sure it is  ${FirstName} and not $FirstName?
0
 
LVL 29

Expert Comment

by:Badotz
ID: 34146962
Are you doing this on the client? Have you given a thought to security?
0
 

Author Comment

by:rutledgj
ID: 34148700
OK. So I changed it to use diff variables and it doesn't complain about line 5. Now it says the syntac of the db driver is incorrect.  My code now looks like this:

 
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://host:port/dbname','','');

dbConn.close();var dbConn = DatabaseConnectionFactory.createDatabaseConnection ('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://localhost:1433/Demographics','MirthUser','b9isnice');

var fname = $('FirstName');
var mname = $('MiddleName');
var lname = $('LastName');
var patientid = $('PatientID');
var gender = $('Sex');
var ssn = $('myssn');
var phone = $('HomePhone');
var addr = $('Address1');
var city = $('City');
var st = $('State');
var zip = $('Zip');

if (MsgType == 'ADTA08')
{
 
var sql="INSERT INTO Patient (PatientID,FirstName,MiddleName,LastName,Gender,SSN,HomePhone,HomeAddress1,City,State,Zip) values("+patientid+",'"+fname+"','"+mname+"','"+lname+"','"+gender+"','"+ssn+"','"+phone+"','"+addr+"','"+city+"','"+st+"','"+zip+"')";

logger.error("Query is: " + sql);



var status=dbConn.executeUpdate(sql);



}


dbConn.close();

Open in new window

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question