Solved

javascript question for inserting record in sql server

Posted on 2010-11-16
4
587 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

726 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