0

I'm having problem executing this query. It always shows

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Terminated, ExtendedWorkAbsences, LearningProcedureRetainingInfo, DisciplineWage' at line 1" error.

function addData(dataNe){
var connectionName = 'xxxxxxx';
var user = 'xxxxx';
var userPwd = 'xxxxx';
var db = 'xxxxxx';

var dbUrl =  'jdbc:google:mysql://' + connectionName + '/' + db;

var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);

var stmt = conn.prepareStatement('INSERT INTO ReferenceResponse '
+ '(Code, ContactEmail, ContactName, ContactAddress, ContactPhone, ContactPreference, ContactOccupation, ContactAssociation,'
+ ' ConfidentialResponses, EmployerName, WorkReferencePosition, WorkLength, WorkSeparation, Terminated, ExtendedWorkAbsences,'
+ ' LearningProcedureRetainingInfo, DisciplineWageGarnishment, PolicyProcedure, FrequentlyLateUnreliable, WorkPerformanceIssue,'
+ ' AssociationLength, ContactFrequency, Interaction, Temperament, Finances, Communication, Emergencies, JudgementDecisionMaking,'
+ ' DishonestUntrustworthy, Temper, ImmoralUnethicalBehavior, DomesticViolence, SubstanceAbuse, BiasPrejudice, RecommendPosition,'
+ ' FurtherExplanation, ContactSignature, ResponseDate, AddedBy, AddedOn, UpdatedBy, UpdatedOn)'
+ ' values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)');

stmt.setString(1, dataNe.candidate_code.toUpperCase());
stmt.setString(2, dataNe.email.toLowerCase());
stmt.setString(3, dataNe.fullname);
stmt.setString(4, dataNe.address);
stmt.setString(5, dataNe.phonenumber);
stmt.setString(6, dataNe.besttime);
stmt.setString(7, dataNe.occupation);
stmt.setString(8, dataNe.asso_candi);
stmt.setString(9, dataNe.xx);
stmt.setString(10, dataNe.empname);
stmt.setString(11, dataNe.emp_position);
stmt.setString(12, dataNe.emp_length);
stmt.setString(13, dataNe.emp_circumstance);
stmt.setString(14, dataNe.emp_terminate);
stmt.setString(15, dataNe.emp_extendwork);
stmt.setString(16, dataNe.emp_learn);
stmt.setString(17, dataNe.emp_discipline);
stmt.setString(18, dataNe.emp_policy);
stmt.setString(19, dataNe.emp_notdepend);
stmt.setString(20, dataNe.emp_performanceissue);
stmt.setString(21, dataNe.year);
stmt.setString(22, dataNe.contact);
stmt.setString(23, dataNe.along);
stmt.setString(24, dataNe.temperament);
stmt.setString(25, dataNe.financial);
stmt.setString(26, dataNe.communication);
stmt.setString(27, dataNe.emergencies_situ);
stmt.setString(28, dataNe.poor_judg);
stmt.setString(29, dataNe.untrust);
stmt.setString(30, dataNe.lose_control);
stmt.setString(31, dataNe.unethical_beha);
stmt.setString(32, dataNe.domestic_violence);
stmt.setString(33, dataNe.alcohol);
stmt.setString(34, dataNe.prejudice);
stmt.setString(35, dataNe.recommend_posi);
stmt.setString(36, dataNe.additional_info);
stmt.setString(37, dataNe.ContactSignature);
stmt.setTimestamp(38, Jdbc.parseTimestamp(Utilities.formatDate(new Date(dataNe.ResponseDate), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss')));
stmt.setString(39, dataNe.Signature);
stmt.setTimestamp(40, Jdbc.parseTimestamp(Utilities.formatDate(new Date(dataNe.date), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss')));
stmt.setString(41, "");
stmt.setTimestamp(42, Jdbc.parseTimestamp(Utilities.formatDate(new Date(dataNe.ResponseDate), Session.getScriptTimeZone(), 'yyyy-MM-dd HH:mm:ss')));
stmt.execute();
stmt.close();
conn.close();
}

I already look at my code carefully and I believe there's nothing wrong with it, but it still says error.

Any help will be appreciated. Thank you very much!

Cooper
  • 59,616
  • 6
  • 23
  • 54
RJ Villamer
  • 27
  • 13
  • 1
    `TERMINATED` is a MySQL [reserved keyword](https://dev.mysql.com/doc/refman/8.0/en/keywords.html). Fix it by surrounding the column with backticks: see also https://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql/23446378#23446378 – Luke Woodward Jan 14 '20 at 18:12
  • Working. Thanks! – RJ Villamer Jan 16 '20 at 00:14

0 Answers0